結果
問題 | No.747 循環小数N桁目 Hard |
ユーザー | tenten |
提出日時 | 2023-01-10 09:31:18 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 152 ms / 2,000 ms |
コード長 | 2,269 bytes |
コンパイル時間 | 2,841 ms |
コンパイル使用メモリ | 91,088 KB |
実行使用メモリ | 53,168 KB |
最終ジャッジ日時 | 2024-06-01 06:40:20 |
合計ジャッジ時間 | 17,837 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 57 ms
50,372 KB |
testcase_01 | AC | 59 ms
50,144 KB |
testcase_02 | AC | 57 ms
50,488 KB |
testcase_03 | AC | 57 ms
50,172 KB |
testcase_04 | AC | 56 ms
50,536 KB |
testcase_05 | AC | 58 ms
50,440 KB |
testcase_06 | AC | 58 ms
50,536 KB |
testcase_07 | AC | 57 ms
50,128 KB |
testcase_08 | AC | 57 ms
50,016 KB |
testcase_09 | AC | 57 ms
50,088 KB |
testcase_10 | AC | 58 ms
50,568 KB |
testcase_11 | AC | 58 ms
50,440 KB |
testcase_12 | AC | 58 ms
50,472 KB |
testcase_13 | AC | 58 ms
49,988 KB |
testcase_14 | AC | 58 ms
50,368 KB |
testcase_15 | AC | 59 ms
50,004 KB |
testcase_16 | AC | 59 ms
50,384 KB |
testcase_17 | AC | 58 ms
50,052 KB |
testcase_18 | AC | 57 ms
50,548 KB |
testcase_19 | AC | 58 ms
50,324 KB |
testcase_20 | AC | 59 ms
50,192 KB |
testcase_21 | AC | 58 ms
50,620 KB |
testcase_22 | AC | 57 ms
50,180 KB |
testcase_23 | AC | 57 ms
50,448 KB |
testcase_24 | AC | 57 ms
50,448 KB |
testcase_25 | AC | 57 ms
50,408 KB |
testcase_26 | AC | 55 ms
50,296 KB |
testcase_27 | AC | 57 ms
50,236 KB |
testcase_28 | AC | 56 ms
50,108 KB |
testcase_29 | AC | 57 ms
50,348 KB |
testcase_30 | AC | 56 ms
50,496 KB |
testcase_31 | AC | 56 ms
50,400 KB |
testcase_32 | AC | 59 ms
50,116 KB |
testcase_33 | AC | 106 ms
52,012 KB |
testcase_34 | AC | 75 ms
51,192 KB |
testcase_35 | AC | 75 ms
50,852 KB |
testcase_36 | AC | 78 ms
51,172 KB |
testcase_37 | AC | 66 ms
50,524 KB |
testcase_38 | AC | 80 ms
51,060 KB |
testcase_39 | AC | 76 ms
51,044 KB |
testcase_40 | AC | 108 ms
51,984 KB |
testcase_41 | AC | 103 ms
51,872 KB |
testcase_42 | AC | 102 ms
51,696 KB |
testcase_43 | AC | 78 ms
51,164 KB |
testcase_44 | AC | 102 ms
51,816 KB |
testcase_45 | AC | 106 ms
51,976 KB |
testcase_46 | AC | 100 ms
51,684 KB |
testcase_47 | AC | 104 ms
51,912 KB |
testcase_48 | AC | 80 ms
50,956 KB |
testcase_49 | AC | 82 ms
51,264 KB |
testcase_50 | AC | 78 ms
51,216 KB |
testcase_51 | AC | 76 ms
51,156 KB |
testcase_52 | AC | 83 ms
51,232 KB |
testcase_53 | AC | 133 ms
52,148 KB |
testcase_54 | AC | 118 ms
51,944 KB |
testcase_55 | AC | 145 ms
53,168 KB |
testcase_56 | AC | 116 ms
52,056 KB |
testcase_57 | AC | 77 ms
51,128 KB |
testcase_58 | AC | 152 ms
52,064 KB |
testcase_59 | AC | 85 ms
51,420 KB |
testcase_60 | AC | 124 ms
52,208 KB |
testcase_61 | AC | 94 ms
51,600 KB |
testcase_62 | AC | 110 ms
51,780 KB |
testcase_63 | AC | 109 ms
51,936 KB |
testcase_64 | AC | 78 ms
50,984 KB |
testcase_65 | AC | 65 ms
50,192 KB |
testcase_66 | AC | 99 ms
51,764 KB |
testcase_67 | AC | 77 ms
51,056 KB |
testcase_68 | AC | 103 ms
51,532 KB |
testcase_69 | AC | 100 ms
52,084 KB |
testcase_70 | AC | 79 ms
51,172 KB |
testcase_71 | AC | 74 ms
51,212 KB |
testcase_72 | AC | 81 ms
51,016 KB |
testcase_73 | AC | 103 ms
51,880 KB |
testcase_74 | AC | 90 ms
51,380 KB |
testcase_75 | AC | 78 ms
51,012 KB |
testcase_76 | AC | 82 ms
50,936 KB |
testcase_77 | AC | 81 ms
51,172 KB |
testcase_78 | AC | 104 ms
51,880 KB |
testcase_79 | AC | 80 ms
51,228 KB |
testcase_80 | AC | 103 ms
51,704 KB |
testcase_81 | AC | 75 ms
51,252 KB |
testcase_82 | AC | 80 ms
50,940 KB |
testcase_83 | AC | 75 ms
51,220 KB |
testcase_84 | AC | 103 ms
52,232 KB |
testcase_85 | AC | 104 ms
52,128 KB |
testcase_86 | AC | 94 ms
51,660 KB |
testcase_87 | AC | 106 ms
51,924 KB |
testcase_88 | AC | 83 ms
51,412 KB |
testcase_89 | AC | 81 ms
50,856 KB |
testcase_90 | AC | 88 ms
51,364 KB |
testcase_91 | AC | 107 ms
52,060 KB |
testcase_92 | AC | 81 ms
50,904 KB |
testcase_93 | AC | 101 ms
52,076 KB |
testcase_94 | AC | 111 ms
52,016 KB |
testcase_95 | AC | 124 ms
51,992 KB |
testcase_96 | AC | 120 ms
52,156 KB |
testcase_97 | AC | 115 ms
52,092 KB |
testcase_98 | AC | 150 ms
53,160 KB |
testcase_99 | AC | 123 ms
52,204 KB |
testcase_100 | AC | 129 ms
52,212 KB |
testcase_101 | AC | 94 ms
51,500 KB |
testcase_102 | AC | 99 ms
51,540 KB |
testcase_103 | AC | 105 ms
52,196 KB |
testcase_104 | AC | 107 ms
51,876 KB |
testcase_105 | AC | 107 ms
51,976 KB |
testcase_106 | AC | 107 ms
52,032 KB |
testcase_107 | AC | 106 ms
52,260 KB |
testcase_108 | AC | 106 ms
52,188 KB |
testcase_109 | AC | 104 ms
52,320 KB |
testcase_110 | AC | 107 ms
52,096 KB |
testcase_111 | AC | 105 ms
51,872 KB |
testcase_112 | AC | 106 ms
52,284 KB |
testcase_113 | AC | 106 ms
52,172 KB |
testcase_114 | AC | 106 ms
52,232 KB |
testcase_115 | AC | 106 ms
51,808 KB |
testcase_116 | AC | 106 ms
52,172 KB |
testcase_117 | AC | 106 ms
51,868 KB |
testcase_118 | AC | 105 ms
52,048 KB |
testcase_119 | AC | 105 ms
52,084 KB |
testcase_120 | AC | 106 ms
52,284 KB |
testcase_121 | AC | 106 ms
52,172 KB |
testcase_122 | AC | 105 ms
52,088 KB |
testcase_123 | AC | 106 ms
52,164 KB |
ソースコード
import java.io.*; import java.util.*; import java.util.stream.*; public class Main { static final int MOD = 1000000007; public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int[] arr = new int[]{2, 8, 5, 7, 1, 4}; long n = 0; for (char c : sc.next().toCharArray()) { n *= 10; n += c - '0'; n %= arr.length; } long idx = 1; char[] base = sc.next().toCharArray(); for (int i = base.length - 1; i >= 0; i--) { idx *= pow(n, base[i] - '0', arr.length); idx %= arr.length; n = pow(n, 10, arr.length); } int ans = (int)((idx + arr.length - 1) % arr.length); System.out.println(arr[ans]); } static long pow(long x, int p, int m) { if (p == 0) { return 1; } else if (p % 2 == 0) { return pow(x * x % m, p / 2, m); } else { return pow(x, p - 1, m) * x % m; } } } class Utilities { static String arrayToLineString(Object[] arr) { return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n")); } static String arrayToLineString(int[] arr) { return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new)); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public int[] nextIntArray() throws Exception { return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }