POJ 2109 :Power of Cryptography
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 18258 | Accepted: 9208 |
Description
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
Output
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的更多相关文章
- POJ 1459:Power Network(最大流)
http://poj.org/problem?id=1459 题意:有np个发电站,nc个消费者,m条边,边有容量限制,发电站有产能上限,消费者有需求上限问最大流量. 思路:S和发电站相连,边权是产能 ...
- POJ 2406:Power Strings
Power Strings Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 41252 Accepted: 17152 D ...
- POJ 1459:Power Network 能源网络
Power Network Time Limit: 2000MS Memory Limit: 32768K Total Submissions: 25414 Accepted: 13247 D ...
- 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 ...
- 贪心 POJ 2109 Power of Cryptography
题目地址:http://poj.org/problem?id=2109 /* 题意:k ^ n = p,求k 1. double + pow:因为double装得下p,k = pow (p, 1 / ...
- POJ 2109 -- Power of Cryptography
Power of Cryptography Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 26622 Accepted: ...
- POJ 2109 Power of Cryptography 数学题 double和float精度和范围
Power of Cryptography Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 21354 Accepted: 107 ...
- poj 2109 Power of Cryptography
点击打开链接 Power of Cryptography Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 16388 Ac ...
- POJ:2109-Power of Cryptography(关于double的误差)
Power of Cryptography Time Limit: 1000MS Memory Limit: 30000K Description Current work in cryptograp ...
随机推荐
- Java知多少(4)J2SE、J2EE、J2ME的区别
原文:Java知多少(4)J2SE.J2EE.J2ME的区别 1998年12月,SUN公司发布了Java 1.2,开始使用“Java 2” 这一名称,目前我们已经很少使用1.2之前的版本,所以通常所说 ...
- Paypal-Express Checkout快捷支付方式的android端开发心得(二)
一.前导 上一篇讲的不是非常好,这里再又一次讲一下. Paypal手机支付有2种形式: 1.Mobile Express Checkout,MEC,快捷支付 2.MPL 假设採用MEC支付方式,这样的 ...
- IOS应用上传须要做的工作
苹果开发人员 https://developer.apple.com/ 证书创建流程 certificates (证书): 是电脑可以增加开发人员计划的凭证 证书分为:开发证书和公布(产品)证书, ...
- js 模块化的规范
The Module Pattern,模块模式,也译为模组模式,是一种通用的对代码进行模块化组织与定义的方式.这里所说的模块(Modules),是指实现某特定功能的一组方法和代码.许多现 ...
- Scan IP relocate/failover其它段后不能ping通过
或手动集群重启单个节点srvctl relocate scan_listener后.群集网络段ping IP,VIP.SCAN IP正常.其他段ping SCAN IP 不通.其原因是,该路由ARP表 ...
- mysql压力测试
1.采用 mysqlslap 压力测试 mysqlslap --defaults-file=/etc/my.cnf --concurrency=200 --iterations=1 --numbe ...
- 注册表 ControlSet001、ControlSet002以及CurrentControlSet
首先说说ControlSet几组控制之间的关系. 注册表HKLM\system注意 注册表项包含windows启动的三个控件组(额外还可能存在一个备份控件组).在初始状态下.它们各自是Con ...
- hibernate几个纯sql查询
几个hibernate纯SQL询问,查询和表没有映射pojo实体和表有映射关系的实体...... 1.getSession().createSQLQuery(sql).query.addScalar( ...
- android 有效载荷大图,避OOM
我们的项目往往会载入图片.有时,承担太多,再装图片,它导致了非常小的程序卡,而在铅oom从而导致异常app再见,今天翻译google官方网站,它已经做了很好的图像处理汇总,由于Google我们已经给解 ...
- 我国常用的坐标系统WKID列表[转]
原文链接:http://blog.sina.com.cn/s/blog_62f9ffcd0102uw8x.html Geographic Coordinate System 地理坐标 4214 GC ...