Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 18258   Accepted: 9208

Description

Current work in cryptography involves (among other things) large prime numbers and computing powers of numbers among these primes. Work in this area has resulted in the practical use of results from number theory and other branches of mathematics once considered
to be only of theoretical interest. 

This problem involves the efficient computation of integer roots of numbers. 

Given an integer n>=1 and an integer p>= 1 you have to write a program that determines the n th positive root of p. In this problem, given such integers n and p, p will always be of the form k to the nth. power, for an integer k (this integer is
what your program must find).

Input

The input consists of a sequence of integer pairs n and p with each integer on a line by itself. For all such pairs 1<=n<= 200, 1<=p<10101 and there exists an integer k, 1<=k<=109 such that kn = p.

Output

For each integer pair n and p the value k should be printed, i.e., the number k such that k n =p.

Sample Input

2 16
3 27
7 4357186184021382204544

Sample Output

4
3
1234

这题有多坑。

。不想多说了。

。開始被那101次方被吓尿了。

还有坑爹的是我用G++提交就WA。

改C++就AC。。我真不知道怎么说才好。。

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath> using namespace std; int main()
{
double n, m;
while(scanf("%lf%lf", &n, &m)!=EOF)
{
printf("%.0lf\n", pow(m, 1/n));
} return 0;
}

注:这才是正常的吧。。。

#include<stdio.h>
#define N 1100
int n,a[N],k[10];
char p[N];
void pown()
{
int i,j,g,b[N];
for(i=1;i<N;i++)a[i]=0;
a[0]=1;
for(g=0;g<n;g++){
for(i=0;i<N;i++){
b[i]=a[i];
a[i]=0;
}
for(i=0;i<N;i++)
for(j=0;j<10;j++)
a[i+j]+=b[i]*k[j];
for(i=0;i<N-1;i++){
a[i+1]+=a[i]/10;
a[i]%=10;
}
}
}
int main()
{
int i,j,t;
while(~scanf("%d%s",&n,p)){
for(i=0;i<10;i++)k[i]=0;
for(t=0;p[t];t++)a[t]=p[t]-48;
for(j=t;t<N;t++)p[t]=0;
j--;
for(i=0,t=j;i<t,j>=0;i++,j--)p[j]=a[i];//倒置p
for(i=0;i<N;i++)a[i]=0;
for(i=9;i>=0;i--){// 从最高到个位依次确定
for(k[i]=9;k[i]>0;k[i]--){ //第i位上的值从9到0依次尝试
pown();//求k的n次方
for(j=N-1;j>0;j--)
if(a[j]!=p[j])break;
if(a[j]<=p[j])break;
//假设a(即此时的k^n值)小于等于p那么k的第i位值为当前值
}
}
for(i=9;i>0;i--)
if(k[i])break;
for(;i>=0;i--)printf("%d",k[i]);
puts("");
}
return 0;
}

版权声明:本文博客原创文章,博客,未经同意,不得转载。

POJ 2109 :Power of Cryptography的更多相关文章

  1. POJ 1459:Power Network(最大流)

    http://poj.org/problem?id=1459 题意:有np个发电站,nc个消费者,m条边,边有容量限制,发电站有产能上限,消费者有需求上限问最大流量. 思路:S和发电站相连,边权是产能 ...

  2. POJ 2406:Power Strings

    Power Strings Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 41252   Accepted: 17152 D ...

  3. POJ 1459:Power Network 能源网络

    Power Network Time Limit: 2000MS   Memory Limit: 32768K Total Submissions: 25414   Accepted: 13247 D ...

  4. 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 ...

  5. 贪心 POJ 2109 Power of Cryptography

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

  6. POJ 2109 -- Power of Cryptography

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

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

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

  8. poj 2109 Power of Cryptography

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

  9. POJ:2109-Power of Cryptography(关于double的误差)

    Power of Cryptography Time Limit: 1000MS Memory Limit: 30000K Description Current work in cryptograp ...

随机推荐

  1. iOS开发- Xcode插件(一)-规范凝视生成器VVDocumenter

    分享几个经常使用的Xcode插件. 第一个, 规范凝视生成器VVDocumenter. 顾名思义, 它能够非常方便的为你自己主动加入�凝视 使用效果例如以下: 下载链接:https://github. ...

  2. 【SEO 决胜网络索引】 课程大纲及第一部分第一课:网络营销战略中的索引

    内容简介 1.课程大纲 2.第一部分第一课: 网络营销战略中的索引 3.第一部分第二课预告: 索引是什么 课程大纲 现在是网络为王的时代,人们越来越离不开互联网: SEO(Search Engine ...

  3. iOS pragma mark要使用

    郝萌主倾心贡献,尊重作者的劳动成果.请勿转载. 假设文章对您有所帮助.欢迎给作者捐赠.支持郝萌主,捐赠数额任意.重在心意^_^ 我要捐赠: 点击捐赠 Cocos2d-X源代码下载:点我传送 简单的来说 ...

  4. HDU 3715 Go Deeper(2-sat)

    HDU 3715 Go Deeper 题目链接 题意:依据题意那个函数,构造x数组.问最大能递归层数 思路:转化为2-sat问题,因为x仅仅能是0.1,c仅仅能是0,1.2那么问题就好办了,对于0, ...

  5. shell script 入门 笔记

    shell script 入门 在 shell script 注意必须使用完全相同写在下面: 1.  指令的运行是从上而下.从左而右的分析与运行: 2.  指令的运行就如同第五章内提到的: 指令.选项 ...

  6. C random C ++rand函数应用

    random函数不是ANSI C标准,不能在gcc,vc等编译器下编译通过.但在C语言中int random(num)能够这样使用,它返回的是0至num-1的一个随机数. 可改用C++下的rand函数 ...

  7. JAVA中类以及成员变量和成员方法的修饰符的总结

    一  类的修饰符 java中的文件结构由大到小为:一个工程,一个工程下可以有许多包,每个包中可以有许多类. 类的修饰符分为         访问权限修饰符          和             ...

  8. Oracle中merge into的使用 (转)

    http://blog.csdn.net/yuzhic/article/details/1896878 http://blog.csdn.net/macle2010/article/details/5 ...

  9. Android 应用程序窗口显示状态操作(requestWindowFeature()的应用)

     我们在开发程序是常常会须要软件全屏显示.自己定义标题(使用button等控件)和其它的需求,今天这一讲就是怎样控制Android应用程序的窗口显示. 首先介绍一个重要方法那就是requestWi ...

  10. crm创建报告补充导航

    报告导航实现动态交互体验报告. 通过使用各种类型的操作的,报告允许用户导航到特定的报告.Microsoft Dynamics CRM 记录或其它网站 动态钻取到 Microsoft Dynamics ...