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. [LeetCode119]Pascal's Triangle II

    题目: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [ ...

  2. C++使用对象指针

    //定义结构 Box.h: #ifndef BOX_H #define BOX_H struct Box{ double length; double width; double height; do ...

  3. Centos6.5下一个Ceph存储集群结构

    简单的介绍 Ceph的部署模式下主要包括下面几个类型的节点 • Ceph OSDs: A Ceph OSD 进程主要用来存储数据,处理数据的replication,恢复,填充.调整资源组合以及通过检查 ...

  4. Raw-OS互斥的源代码分析的量的Mutex

    作为分析的内核版本2014-04-15,基于1.05正式版.blogs我们会跟上的内核开发进度的最新版本,如果出现源代码的目光"???"的话,没有深究的部分是理解. Raw-OS官 ...

  5. Mysql 5.6 新特性

    随笔,真的随笔,以后理解得更深了再修改.   Index Condition Pushdown 更多的让存储引擎去处理Where语句中的条款,避免返回无关字段数据等:   Multi-Range Re ...

  6. 开源 自由 java CMS - FreeCMS2.0 举APP产生信息数据

    项目地址:http://www.freeteam.cn/ 生成信息数据 生成当前管理网站下同意移动APP訪问的栏目的信息页面. 从左側管理菜单点击生成信息数据进入. 您能够选择须要生成的栏目,然后点击 ...

  7. cocos2dx lua

    对于游戏公司而言.採用游戏脚本lua.python等进行开发也非经常见,可是非常多童鞋对脚本并没有非常熟悉的概念,本篇则向大家简介脚本的用途以及在Cocos2dx基础使用方法: Lua和python这 ...

  8. WPF学习(3)布局

    今天我们来说说WPF的布局.我们知道WinForm的布局主要是采用基于坐标的方式,当窗口内容发生变化时,里面的控件不会随之动态调整,这就造成了一个很不好的用户体验.而WPF为了避免这个缺点,采用了基于 ...

  9. WinJS Clipboard

    //剪贴板 方法1 window.uexClipboard = { copy: null, getContent: null, cbGetContent: null }; uexClipboard.c ...

  10. python2编码总结(转)

    以下依次列出python2常遇到的几个问题及讲解. # -*- coding:utf-8 -*- python2默认以ASCII编码,但是在实际编码过程中,我们会用到很多中文,为了不使包含中文的程序报 ...