http://lightoj.com/volume_showproblem.php?problem=1282
The first three digits and the last three digits of the K-square of n are then output
The last three bits are made with a quick power, and I just don't get a quick power at first, and then slowly understand.
The first three are more powerful.
We can do it. n^k = A.BC * 10.0^M;
K*LOG10 (n) = log10 (A.BC) + M;
M is the integral part of K * LG (N), and LG (A.BC) is a fractional part of K * LG (n);
x = log10 (A.BC) = K*LOG10 (n)-m = K*LOG10 (n)-(int) k*log10 (n);
x = POW (10.0, x);
#include <stdio.h>#include<string.h>#include<stdlib.h>#include<algorithm>#include<stdio.h>#include<string.h>#include<stdlib.h>#include<math.h>#include<algorithm>#include<iostream>#include<vector>#include<queue>using namespaceStd;typedefLong Long intLL;#defineN 1001000#defineESP 1e-8#defineINF 0x3f3f3f3f#defineMemset (A, B) memset (A,b,sizeof (a))intPow (intAintBintc) { if(b = =0) return 1; LL T= Pow (A, b>>1, c); T= t*t%C; if(b%2==1) T= t*a%C; returnt;}///Fast PowerintMain () {intT, t=1; scanf ("%d", &T); while(T--) { intN, K; scanf ("%d%d", &n, &k); Doublem = K*LOG10 (n)-(LL) (k*log10 (n)); M= POW (10.0, M); intAns = Pow (n, K, +); printf ("Case %d:%d%03d\n", t++, (int) (m* -), ans); } return 0;}
1282-leading and Trailing---LightOj1282 (fast power + math)