import java.math.BigInteger;
import java.util.Scanner;
public class Main {
static BigInteger p,l,r,div;
static int n;
public static int cmp(BigInteger mid){
BigInteger sum=mid.pow(n);
return sum.compareTo(p);
}
public static BigInteger calc(){
l=BigInteger.ZERO;
r=BigInteger.valueOf(1000000000);
BigInteger div=BigInteger.valueOf(2);
while(l.compareTo(r)<0){
BigInteger mid=l.add(r).divide(div);
int fl=cmp(mid);
if(fl==0){
return mid;
}
else if(fl==-1){
l=mid.add(BigInteger.ONE);
}
else r=mid;
}
int fl=0;
if((fl=cmp(r))==0)return r;
if(fl==-1){
while(p.subtract(r.pow(n)).compareTo(BigInteger.ONE)>0)r=r.add(BigInteger.ONE);
return r;
}
else {
while(r.pow(n).subtract(p).compareTo(BigInteger.ONE)>0)r=r.subtract(BigInteger.ONE);
return r;
}
}
public static void main(String args[]){
Scanner scanner=new Scanner(System.in);
while(scanner.hasNext()){
n=scanner.nextInt();
p=scanner.nextBigInteger();
BigInteger ans=calc();
System.out.println(ans);
}
}
}

有种更为优雅的姿势

#include <cstdio>
#include <cmath> int main()
{
double n , m ;
int ans ;
while ( scanf( "%lf%lf" , &m , &n ) != EOF )
printf( "%.0f\n" , exp(log(n)/m) ) ;
}

另附大神证明思路:泰勒公式证明相差不会超过9

http://blog.csdn.net/synapse7/article/details/11672691

POJ 2109 Power of Cryptography 大数,二分,泰勒定理 难度:2的更多相关文章

  1. 贪心 POJ 2109 Power of Cryptography

    题目地址:http://poj.org/problem?id=2109 /* 题意:k ^ n = p,求k 1. double + pow:因为double装得下p,k = pow (p, 1 / ...

  2. POJ 2109 -- Power of Cryptography

    Power of Cryptography Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 26622   Accepted: ...

  3. POJ 2109 Power of Cryptography 数学题 double和float精度和范围

    Power of Cryptography Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 21354 Accepted: 107 ...

  4. poj 2109 Power of Cryptography

    点击打开链接 Power of Cryptography Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 16388   Ac ...

  5. POJ - 2109 Power of Cryptography(高精度log+二分)

    Current work in cryptography involves (among other things) large prime numbers and computing powers ...

  6. POJ 2109 Power of Cryptography【高精度+二分 Or double水过~~】

    题目链接: http://poj.org/problem?id=2109 参考: http://blog.csdn.net/code_pang/article/details/8263971 题意: ...

  7. poj 2109 Power of Cryptography (double 精度)

    题目:http://poj.org/problem?id=2109 题意:求一个整数k,使得k满足kn=p. 思路:exp()用来计算以e为底的x次方值,即ex值,然后将结果返回.log是自然对数,就 ...

  8. Poj 2109 / OpenJudge 2109 Power of Cryptography

    1.Link: http://poj.org/problem?id=2109 http://bailian.openjudge.cn/practice/2109/ 2.Content: Power o ...

  9. POJ 2109 :Power of Cryptography

    Power of Cryptography Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 18258   Accepted: ...

随机推荐

  1. Windows10 蓝屏 DRIVER_IRQL_NOT_LESS_OR_EQUAL (vfilter.sys)的可能解决方法

    早上我的笔记本从休眠中开机的时候突然出现了蓝屏,这个蓝屏在前几天出现过了.两次提示的终止代码都一样.我的笔记本型号是DELL XPS15 9560 我的笔记本配置: 类别 型号 内存 16GB DDR ...

  2. my normal Header

    #ifndef INCLUDES_MY #define INCLUDES_MY //默认登录名密码 #define DEFAULT_USERNAME "admin" #define ...

  3. hdoj-2028-Lowest common multiple plus

    题目:Lowest common multiple plus 代码: #include<stdio.h> int common(int a,int b)//计算最大公约数 { int c= ...

  4. 【TCP/IP详解 卷一:协议】第十七章 TCP:传输控制协议

    本章作为TCP的入门章节,简单的概述了一些TCP的知识,和TCP数据报的首部格式. TCP 最重要的特性:reliable. 17.1 引言 本章介绍的是 TCP为应用层提供的服务. 17.2 TCP ...

  5. javascript的一些在IE下不支持的函数小结

    // ============ isArray ===============// // isArray function isArray(value){ return Object.prototyp ...

  6. python 进程锁

    1. #_*_coding:utf-8_*_ from multiprocessing import Process,Lock import os,time def f(l,i): #加锁 l.acq ...

  7. 遇到Io阻塞时会切换任务之【爬虫版】

    #! /usr/bin/env python3 # -*- coding:utf- -*- from urllib import request import gevent,time from gev ...

  8. shell 跳出循环

    跳出循环 break命令 例: #!/bin/bash while : do echo -n "输入 1 到 5 之间的数字:" read aNum case $aNum in 1 ...

  9. SQL 存储过程中的IF_BEGIN_END作用域

    USE [DB_NAME] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER PROCEDURE [DBO].[PROC_TEST_I ...

  10. PHP概率,抽奖

    随机数,游标卡尺. 一个大饼,随机到哪个坑里,就中哪个奖. 大转盘! 公平公正! // 获取锦鲤 public function getGoldPig() { $pig_gift_bag = [ [ ...