题目链接:点击这里
构造函数: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));
}
}
}