UVA 113Power of Cryptography
来源:互联网 发布:广州新科佳都科技 知乎 编辑:程序博客网 时间:2024/05/21 01:56
UVA-113 Power of Cryptography
题目大意:1 <= n <= 200, 1 <= p <= 10^101, k^n = p, 已知 n, p, 求 k。
Sample Input
2
16
3
27
7
4357186184021382204544
Sample Output
4
3
1234
解题思路:这个题思路是先求1+2+3+……+n>k的最小n,然后判断1+2+……+n的和减去k是否为偶数,若为偶数,则n即为所求,若不是,则n++重复刚才的判断。把k都当做正数做,它们只差了个符号,在本题没有影响。 0 比较特殊,须另外判断。
//UVA-465 Overflow#include <iostream>#include <cstdio>#include <climits>#include <cstdlib>using namespace std;const int inf = INT_MAX; //INT_MAX头文件 climitsint main() { double a, b; char s1[1010],s2,s3[1010]; while (scanf("%s %c %s",s1,&s2,s3) != EOF) { printf("%s %c %s\n",s1,s2,s3); a = atof(s1); //字符串转换为双精度浮点数(double),头文件 cstdlib b = atof(s3); if (s2 == '+') { if (a > inf) printf("first number too big\n"); if (b > inf) printf("second number too big\n"); if (a + b > inf) printf("result too big\n"); } if (s2 == '*') { if (a > inf) printf("first number too big\n"); if (b > inf) printf("second number too big\n"); if (a * b > inf) printf("result too big\n"); } } return 0;}
参考:
- 二分法+高精度——Poj 2109 Power of Cryptography(double型开n次方的方法通过的原因)
- 浮点数在计算机中的表示
0 0
- UVa 113 Power of Cryptography
- uva 113Power of Cryptography
- uva 113 Power of Cryptography
- UVA 113 - Power of Cryptography
- uva 113 - Power of Cryptography
- UVa 113 - Power of Cryptography
- UVA 113 - Power of Cryptography
- UVa 113Power of Cryptography
- UVa 113: Power of Cryptography
- uva 113 - Power of Cryptography
- UVA 113 Power of Cryptography
- uva 113 Power of Cryptography
- UVA 113 Power of Cryptography
- uva - 113 - Power of Cryptography
- uva 113 power of Cryptography
- UVa 113 - Power of Cryptography
- uva 113 - Power of Cryptography
- UVa 113 - Power of Cryptography
- c3p0结合dbutils 连接释放问题
- Java基础
- python3的文件操作
- 绘制直方图时自适应区间数量
- 使用静态代码块解决避免创建多个相同功能对象
- UVA 113Power of Cryptography
- 编码中关于size_t的一个问题
- Cocos2dx-3.x触摸事件之实现人机交互(三)
- refind 0.10.3 配置文件refind.conf简单分析
- 魏则西事件之后,民营医疗的营销方式
- Jquery Md5加密-Jquery.md5.js
- Java之json和对象之间的相互转换
- Leetcode Restore IP Address
- JavaScript数组的高级用法-reduce和reduceRight详解