結果

問題 No.16 累乗の加算
ユーザー kuramukuramu
提出日時 2016-01-29 11:17:46
言語 Java21
(openjdk 21)
結果
AC  
実行時間 45 ms / 5,000 ms
コード長 926 bytes
コンパイル時間 3,867 ms
コンパイル使用メモリ 71,620 KB
実行使用メモリ 49,708 KB
最終ジャッジ日時 2023-09-08 11:52:45
合計ジャッジ時間 3,529 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
49,344 KB
testcase_01 AC 43 ms
49,524 KB
testcase_02 AC 44 ms
49,148 KB
testcase_03 AC 43 ms
49,572 KB
testcase_04 AC 44 ms
49,544 KB
testcase_05 AC 44 ms
49,240 KB
testcase_06 AC 44 ms
49,144 KB
testcase_07 AC 45 ms
49,348 KB
testcase_08 AC 45 ms
49,296 KB
testcase_09 AC 45 ms
49,588 KB
testcase_10 AC 45 ms
49,312 KB
testcase_11 AC 43 ms
49,524 KB
testcase_12 AC 45 ms
49,516 KB
testcase_13 AC 44 ms
49,708 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) {
	      BufferedReader stdReader =new BufferedReader(new InputStreamReader(System.in));
	      try {
	    	  String[] temp1 = stdReader.readLine().split(" ");
	    	  int x = Integer.parseInt(temp1[0]);
	    	  int N = Integer.parseInt(temp1[1]);
	    	  String[] temp2 = stdReader.readLine().split(" ");
	    	  int ans = 0;	
	    	  for(int i=0;i<N;i++){
	    		  ans = (ans + pow(x, Integer.parseInt(temp2[i]))) % 1000003;
	    	  }
	    	  System.out.println(ans);
	      } catch (IOException e) {
			e.printStackTrace();
	      }
	}
	
	public static int pow(int x,int n){
		long temp = x;
		long ans = 1;
		while(n>0){
			if(n%2==0){
				temp = temp*temp % 1000003;
				n /= 2;
			}else{
				n -= 1;
				ans = ans *temp % 1000003;
			}
		}		
		return (int)ans;
	}
}
0