Ultraviolet A-113 Power of Cryptography (Power of a Large Number + two points)
Open Link
Given n and p, find k to make k ^ n = p. 1 <= k <= 10 ^ 9
We can use a second k to express k ^ n with high precision and then compare it with p.
# Include
# Include
# Include
Const int maxn = 1000000000; struct bign {int len; int f [1500]; bign () {memset (f, 0, sizeof (f )); len = 0 ;}}; int n, ans; char p [150]; bign mul (bign a, bign B) // multiply the large numbers by {bign c; for (int I = 0; i0) {. f [l] = B. f [l] = x % 10; x/= 10; l ++;}. len = B. len = l; for (int I = 1; I
L) return-1; else {for (int I = 0; I
P [I]-'0') {flag =-1; break;} else {. len -- ;}} return flag ;}} void binary (int x, int y) // binary k between x and y {bign a; while (x <= y) {int mid = (x + y)/2; a = solve (mid); int t = compare (a); if (t = 0) {ans = mid; return;} else if (t = 1) x = mid + 1; else y = mid-1;} int main () {// freopen ("a.txt ", "r", stdin); while (~ Scanf ("% d", & n) {getchar; scanf ("% s", p); binary (1, maxn); printf ("% d \ n ", ans);} return 0 ;}
Of course, the faster method is to directly use double.
#include
#include
int main(){ double n,p; while(~scanf("%lf%lf",&n,&p)) { printf("%.0lf\n",pow(p,1.0/n)); } return 0;}