1046 A^B Mod C

时间:2023-03-09 04:30:44
1046 A^B Mod C

1046 A^B Mod C

基准时间限制:1 秒 空间限制:131072 KB

给出3个正整数A B C,求A^B Mod C。

例如,3 5 8,3^5 Mod 8 = 3。

Input

3个正整数A B C,中间用空格分隔。(1 <= A,B,C <= 10^9)

Output

输出计算结果

Input示例

3 5 8

Output示例

3

--------------
快速幂
*/
import java.util.Scanner;
public class Main1 {
static long PowerMod(long a,long b,long c){
long ans=1;
a%=c;
while(b>0){
if((b&1)==1)
ans=(ans*a)%c;
a=(a*a)%c;
b>>=1; }
return ans;
} public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
while(sc.hasNext()){
long a=sc.nextLong();
long b=sc.nextLong();
long c=sc.nextLong();
System.out.println(PowerMod(a,b,c));
}
sc.close();
} }