結果

問題 No.16 累乗の加算
ユーザー holegumaholeguma
提出日時 2015-08-08 20:43:07
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 886 bytes
コンパイル時間 2,209 ms
コンパイル使用メモリ 73,940 KB
実行使用メモリ 51,880 KB
最終ジャッジ日時 2023-09-25 07:17:15
合計ジャッジ時間 3,608 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
49,464 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 45 ms
49,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.StringTokenizer;

class Main{

static final PrintWriter out=new PrintWriter(System.out);
static final int mod=1000003;

public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String line="";
while((line=br.readLine())!=null&&!line.isEmpty()){
StringTokenizer st1=new StringTokenizer(line);
int n=Integer.parseInt(st1.nextToken());
line=br.readLine();
StringTokenizer st2=new StringTokenizer(line);
long ans=0;
while(st2.hasMoreTokens()){
int a=Integer.parseInt(st2.nextToken());
ans+=pow_mod_1000003(n,a);
}
out.println(ans%mod);
out.flush();
}
}
private static long pow_mod_1000003(int n,int a){
if(a==0) return 1;
int sum=1;
char[] bit=Integer.toBinaryString(a).toCharArray();
for(int i=0;i<bit.length;i++){
sum=sum*sum%mod;
if(bit[i]=='1') sum=sum*n%mod;
}
return sum;
}
}
0