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. 玩转Web之Json(一)-----easy ui+ajax + json 中关于Json的解析问题

    在easy ui中使用Ajax+Json实现前后的数据交互时,当后台数据传输到客户端是需对Json数据进行解析,这里将对Json数据解析做简单总结. (一) 对于服务器返回的数据若没有做类型说明,需要 ...

  2. sqlite3触发器的使用

    研究了一下osx下dock中应用的存储,位于~/Library/Application Support/Dock/下一个比較名字比較长的db文件里,之前简单的介绍过osx launchpad图标的删除 ...

  3. hdu 4856 Tunnels(bfs+状态压缩)

    题目链接:hdu 4856 Tunnels 题目大意:给定一张图,图上有M个管道,管道给定入口和出口,单向,如今有人想要体验下这M个管道,问最短须要移动的距离,起点未定. 解题思路:首先用bfs处理出 ...

  4. 【转】JAVA 网络编程

    网络编程 网络编程对于很多的初学者来说,都是很向往的一种编程技能,但是很多的初学者却因为很长一段时间无法进入网络编程的大门而放弃了对于该部分技术的学习. 在 学习网络编程以前,很多初学者可能觉得网络编 ...

  5. [Python学习] 模块三.基本字符串

            于Python最重要的数据类型包含字符串.名单.元组和字典.本文重点介绍Python基础知识. 一.字符串基础         字符串指一有序的字符序列集合,用单引號.双引號.三重(单 ...

  6. Ceph 存储集群

    Ceph 存储集群 Ceph 作为软件定义存储的代表之一,最近几年其发展势头很猛,也出现了不少公司在测试和生产系统中使用 Ceph 的案例,尽管与此同时许多人对它的抱怨也一直存在.本文试着整理作者了解 ...

  7. Visual Studio Team Services使用教程--默认团队checkin权限修改

  8. jquery :操作iframe

    原文 jquery :操作iframe 1. 内容里有两个ifame <iframe id="leftiframe"...</iframe> <iframe ...

  9. 三款经常使用IP发包工具介绍

    AntPower 版权全部© 2003 技术文章http://www.antpower.org 第1 页共14 页AntPower-技术文章三款经常使用IP 发包工具介绍小蚁雄心成员郎国军著lgj@q ...

  10. Gradle增量学习建筑

    请在本系列下面的文章下载Github演示示例代码: git clone https://github.com/davenkin/gradle-learning.git       假设我们Gradle ...