一.题目描述
【问题描述】给定正整数 n, 求 + + · · · + mod 123456789 。其中 mod 表示取余。
【输入格式】输入的第一行包含一个整数 n。
【输出格式】输出一行,包含一个整数,表示答案。
【样例输入】2
【样例输出】257
【样例输入】987654
【样例输出】43636805
二.代码
import java.math.BigInteger;
import java.util.Scanner;
public class test1 {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
BigInteger sum = BigInteger.ZERO;//初始化为0
BigInteger a = BigInteger.valueOf(123456789);//用BigInteger存数
for(int i=1;i<=n;i++){
BigInteger temp = BigInteger.valueOf(i);//记得转换为BigInteger类型
sum=sum.add(temp.pow(8));//幂运算
}
System.out.println(sum.mod(a));//记得还要mod
}
}