HDU 5666 Segment(Java大整数)

题目链接:点击这里
在这里插入图片描述
构造函数:public BigInteger(String val, int radix)

  • val - BigInteger 的字符串表示形式。
  • radix - 要在解释 val 时使用的基数(进制)。
import java.math.BigInteger;
import java.math.BigDecimal;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int t = input.nextInt();
		BigInteger q, p, ans;
        BigInteger one = new BigInteger("1");
        BigInteger two = new BigInteger("2");
		while((t--)!=0) {
			q = input.nextBigInteger();
			p = input.nextBigInteger();
			ans = (q.subtract(one).multiply(q.subtract(two))).divide(two);
			System.out.println(ans.remainder(p));
		}
	}
}
发布了674 篇原创文章 · 获赞 103 · 访问量 11万+

猜你喜欢

转载自blog.csdn.net/qq_42815188/article/details/104014098