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. cmd命令安装、卸载、启动和停止Windows Servic

    1.运行--〉cmd:打开cmd命令框 2.在命令行里定位到InstallUtil.exe所在的位置 InstallUtil.exe 默认的安装位置是在C:/Windows/Microsoft.NET ...

  2. Package libvirt was not found in the pkg-config search path

    关于pip安装libvirt-python的时候提示Package libvirt was not found in the pkg-config search path的问题解决方法 1.一开始以为 ...

  3. IDEA启动时自动报Plugin Error错误

    Plugin Error Problems found loading plugins: Plugin "JBoss Integration" was not loaded: re ...

  4. ZOJ 3469 Food Delivery(区间DP)

    https://vjudge.net/problem/ZOJ-3469 题意:在一条直线上有一个餐厅和n个订餐的人,每个人都有随时间上升的不满意值,从餐厅出发,计算出送完时最小的不满意值总和. 思路: ...

  5. 机器学习-数据可视化神器matplotlib学习之路(三)

    之前学习了一些通用的画图方法和技巧,这次就学一下其它各种不同类型的图.好了先从散点图开始,上代码: from matplotlib import pyplot as plt import numpy ...

  6. RTC(x86)

    RTC 原创,转载请写明出处. 一直以来想写一篇关于RTC的总结,可是人太懒,在读完John Z. Sonmez大伽的<软技能代码之外的生存技能>后,终于下定决心,完成这项早已计划中的任务 ...

  7. EsayUI + MVC + ADO.NET(仓储基础接口)

      1.RepositoryFramework(仓储接口:无外乎就是CRUD) 1.IAddRepository(添加接口) using System; namespace Notify.Infras ...

  8. Qt_QString.indesOf和mid测试

    1.indexOf #define GID_PREFIX "dr_" QString str = "dr__awedr4"; int iIdx = str.in ...

  9. stack_01

    A.添加/移除 A.1.void stack::push(elemValue); // 栈头 添加元素 A.2.void stack::pop(); // 栈头 移除第一个元素 B.随机存取 C.数据 ...

  10. Faster R-CNN: Towards Real-Time Object Detection with Region Proposal Networks论文理解

    一.创新点和解决的问题 创新点 设计Region Proposal Networks[RPN],利用CNN卷积操作后的特征图生成region proposals,代替了Selective Search ...