Links: https://vjudge.net/contest/331993#problem/D
3 gives a positive integer ABC, seeking A ^ B Mod C.
For example, 3 5 8,3 ^ 5 Mod 8 = 3.
Input3 positive integer ABC, separated by a space. (1 <= A, B, C <= 10 ^ 9) Output Sample Input outputs the calculation result
3 5 8
Sample Output
3
#include <cstdio> #include <the iostream> the using namespace STD; int POW ( int A, int B, int C) { int ANS = . 1 , Base = A; // ANS: Results of power; base: base number A the while ( b) { IF (& b . 1 ) // determination is not an odd b { ANS = ( Long Long ) ANS * Base % C; } Base = ( Long Long ) Base*base%c; b = b >> 1; //除2 } return ans; } int main() { int a,b,c; scanf("%d%d%d",&a,&b,&c); printf("%d\n",pow(a,b,c)); }
In fact, it can be used as a template to back off, -. - although I know it is. . .