結果
問題 | No.16 累乗の加算 |
ユーザー | shin |
提出日時 | 2022-05-18 07:58:38 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 76 ms / 5,000 ms |
コード長 | 1,279 bytes |
コンパイル時間 | 7,680 ms |
コンパイル使用メモリ | 75,264 KB |
実行使用メモリ | 50,648 KB |
最終ジャッジ日時 | 2023-10-14 13:51:56 |
合計ジャッジ時間 | 5,891 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 44 ms
49,444 KB |
testcase_01 | AC | 43 ms
49,436 KB |
testcase_02 | AC | 76 ms
50,648 KB |
testcase_03 | AC | 46 ms
49,368 KB |
testcase_04 | AC | 48 ms
49,600 KB |
testcase_05 | AC | 50 ms
49,892 KB |
testcase_06 | AC | 54 ms
49,652 KB |
testcase_07 | AC | 51 ms
49,560 KB |
testcase_08 | AC | 57 ms
49,512 KB |
testcase_09 | AC | 60 ms
50,464 KB |
testcase_10 | AC | 53 ms
49,552 KB |
testcase_11 | AC | 44 ms
49,556 KB |
testcase_12 | AC | 53 ms
49,556 KB |
testcase_13 | AC | 51 ms
49,436 KB |
ソースコード
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; public class No16_2 { static int K = 1000003; public static void main(String[] args) throws IOException{ //累乗の加算 二分累乗法で作り直し String[] text = readStr(); int x = Integer.parseInt(text[0].split(" ")[0]); int N = Integer.parseInt(text[0].split(" ")[1]) , a , i , len; int sum = 0 , rui; int[] r = new int[32]; String bit; r[0] = x; for(i = 1;i < 32;i++) { r[i] = (int)((long)Math.pow(r[i - 1], 2) % K); } for(i = 0;i < N;i++) { rui = 1; a = Integer.parseInt(text[1].split(" ")[i]); bit = Integer.toBinaryString(a); len = bit.length(); for(int k = 0;k < len;k++) { if(bit.charAt(k) == '1') { rui = (int)((long)rui * (long)r[len - k - 1] % K); } } sum = (sum + rui) % K; } System.out.println(sum); } public static String[] readStr() throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); ArrayList<String> list = new ArrayList<>(); do { list.add(br.readLine()); }while(br.ready()); br.close(); String[] text = new String[list.size()]; list.toArray(text); return text; } }