結果

問題 No.16 累乗の加算
ユーザー holegumaholeguma
提出日時 2015-08-08 20:51:32
言語 Java21
(openjdk 21)
結果
AC  
実行時間 47 ms / 5,000 ms
コード長 965 bytes
コンパイル時間 2,291 ms
コンパイル使用メモリ 73,592 KB
実行使用メモリ 49,708 KB
最終ジャッジ日時 2023-09-08 11:44:41
合計ジャッジ時間 3,476 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
49,708 KB
testcase_01 AC 43 ms
49,168 KB
testcase_02 AC 46 ms
49,288 KB
testcase_03 AC 44 ms
49,508 KB
testcase_04 AC 44 ms
49,228 KB
testcase_05 AC 45 ms
49,208 KB
testcase_06 AC 45 ms
49,108 KB
testcase_07 AC 45 ms
49,128 KB
testcase_08 AC 46 ms
49,424 KB
testcase_09 AC 47 ms
49,264 KB
testcase_10 AC 45 ms
49,284 KB
testcase_11 AC 43 ms
49,172 KB
testcase_12 AC 45 ms
49,372 KB
testcase_13 AC 45 ms
49,200 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());
int m=Integer.parseInt(st1.nextToken());
int[] a=new int[m];
line=br.readLine();
StringTokenizer st2=new StringTokenizer(line);
for(int i=0;i<m;i++) a[i]=Integer.parseInt(st2.nextToken());
long ans=0;
for(int i=0;i<m;i++){
ans+=pow_mod_1000003(n,a[i]);
}
out.println(ans%mod);
out.flush();
}
}
private static long pow_mod_1000003(int n,int a){
if(a==0) return 1;
long 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