POJ 2109 巧妙解法

Int最大是10^9.所以一般思路是二分+高精度、但是double 范围是10^(-307)-10^308所以可以用double型。k^n=p.所以有k=p^(1/n)。

见代码:

#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
#include<math.h>

int main()
{
     double n, p;
     while(cin >> n >> p)
     {
         double k;
         k = pow(p, 1.0/n);
         cout << k << endl;
     }
     return 0;
}

时间: 2024-11-25 10:29:42

POJ 2109 巧妙解法的相关文章

贪心 --- 巧妙解法

Moving Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 18319    Accepted Submission(s): 6268 Problem Description The famous ACM (Advanced Computer Maker) Company has rented a floor of a b

POJ 2109 :Power of Cryptography

Power of Cryptography 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. W

POJ 2109 -- Unix ls

 POJ 2109 -- Unix ls Sample Input 10 tiny 2short4me very_long_file_name shorter size-1 size2 size3 much_longer_name 12345678.123 mid_size_name 12 Weaser Alfalfa Stimey Buckwheat Porky Joe Darla Cotton Butch Froggy Mrs_Crabapple P.D. 19 Mr._French Jod

POJ 2182 Lost Cows 巧妙解法

题目 Lost Cows Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11766   Accepted: 7570 Description N (2 <= N <= 8,000) cows have unique brands in the range 1..N. In a spectacular display of poor judgment, they visited the neighborhood 'wat

POJ 2109 Power of Cryptography

http://poj.org/problem?id=2109 题意: 给出两个数n和p,要求p是n的几次方. 思路: 好神奇的题目,我一开始想那就一直除呗,后来又想到了有pow这种公式,居然这么简短就过了,有点不可思议. 1 #include<iostream> 2 #include<cmath> 3 using namespace std; 4 5 int main() 6 { 7 double n, p; 8 while (cin >> n >> p)

Poj 2109 / OpenJudge 2109 Power of Cryptography

1.Link: http://poj.org/problem?id=2109 http://bailian.openjudge.cn/practice/2109/ 2.Content: Power of Cryptography Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 18872   Accepted: 9520 Description Current work in cryptography involves (

POJ - 2109 - Power of Cryptography = 高精度整数

http://poj.org/problem?id=2109 给一个大概100位的高精度整数p,找他的n次方根,貌似题目有问题,不一定会有开根开得尽的情况,这个时候要找的就是最大的根. 那这样有什么意思呢? 这种题按道理要用Java去写的,可以先从p和n的关系找到根的位数,然后在这个范围里面二分会更快. 具体来说,比如22位的p,7次方根,就是22/7的上整,取4位数. 还有就是因为题目的原因,double的精度对100位的高精度整数开根是足够的,也就是不会的话可以试试莽一发long doubl

POJ 2109

1 #include<iostream> 2 #include<stdio.h> 3 #include<math.h> 4 using namespace std; 5 6 int main() 7 { 8 //freopen("acm.acm","r",stdin); 9 long double num; 10 long double k; 11 while(cin>>num>>k) 12 { 13 co

Power of Cryptography - poj 2109

Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 20351   Accepted: 10284 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