1046 a^b mod C reference time limit: 1 seconds space limit: 131072 KB score: 0 Difficulty: Basic collection attention gives 3 positive integers a B C, for A^b Mod c. For example, 3 5 8,3^5 Mod 8 = 3. Input
3 positive integers a B C, separated by a space in the middle. (1 <= a,b,c <= 10^9)
Output
Output calculation results
Input example
3 5 8
Output example
3
Related questions x^a mod p x^2 mod p x^a mod B 640 x^3 mod p 640
Fast power ...
Code:
1#include <vector>2#include <map>3#include <Set>4#include <algorithm>5#include <iostream>6#include <cstdio>7#include <cmath>8#include <cstdlib>9#include <string>Ten#include <cstring> One#include <queue> A#include <stack> - using namespacestd; - thetypedefLong Longll; - - ll Mod_pow (ll x,ll y,ll MoD) - { +ll ans=1; - while(y>0){ + if(y&1) Aans=ans*x%MoD; atx=x*x%MoD; -y>>=1; - } - returnans; - } - in intMain () - { to intA,b,c,n; +scanf"%d%d%d",&a,&b,&c); -printf"%d\n", Mod_pow (a,b,c)); the return 0; *}
1046 A^b Mod C