p次方求和

来源:互联网 发布:并行计算与性能优化 编辑:程序博客网 时间:2024/05/17 20:27

p次方求和

时间限制:1000 ms  |  内存限制:65535 KB
难度:3
描述
一个很简单的问题,求1^p+2^p+3^p+……+n^p的和。
输入
第一行单独一个数字t表示测试数据组数。接下来会有t行数字,每行包括两个数字n,p,
输入保证0<n<=1000,0<=p<=1000。
输出
输出1^p+2^p+3^p+……+n^p对10003取余的结果,每个结果单独占一行。
样例输入
210 110 2
样例输出
55385

import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner scanner=new Scanner(System.in);int times=scanner.nextInt();while(times--!=0){int number=scanner.nextInt();int pow=scanner.nextInt();long result=0;for(int i=1;i<=number;i++){int tempnumber=i;int temppow=pow;int flag=1;while(temppow>0){if(temppow%2==1)flag=flag*tempnumber%10003;tempnumber=tempnumber*tempnumber%10003;temppow=temppow/2;}result=result+flag%10003;result%=10003;}System.out.println(result);}}}