DSTJZ


私信TA

用户名:dotcpp0721777

访问量:4464

签 名:

天下难事,必作于易;天下大事,必作于细。

等  级
排  名 50
经  验 10996
参赛次数 13
文章发表 312
年  龄 18
在职情况 学生
学  校 狗熊岭23届毕业生
专  业

  自我简介:

TA的其他文章


参考代码:

import java.math.BigInteger;
import java.util.Scanner;

public class Main
{   public static void main(String[] args)
	{	Scanner scanner = new Scanner(System.in);
		BigInteger a = scanner.nextBigInteger();
		BigInteger b = scanner.nextBigInteger();
		BigInteger p = scanner.nextBigInteger();
		String res = a.modPow(b, p).toString();//BigInteger内置方法,模意义下取幂
//		long a = scanner.nextLong();
//		long b = scanner.nextLong();
//		long p = scanner.nextLong();
//		long res = modPow(a % p, b, p);//先对a进行一次取余
		System.out.print(res);
	}
//	递归
//	public static long modPow(long a, long b, long p) 
//	{	if(b == 0)
//			return 1;
//		boolean isOdd = (b & 1) == 1;
//		long res = modPow(a, b >> 1, p);
//		if(isOdd)
//			return (res * res % p * a % p) % p;
//		else
//			return res * res % p;
//	}
//	迭代方法
//	public static long modPow(long a, long b, long p)
//	{	long res = 1;
//		while(b > 0)
//		{	if((b & 1) == 1)
//				res *= a;
//			a *= a;
//			res %= p;
//			a %= p;
//			b >>= 1;
//		}
//		return res;
//	}
}


 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区