結果

問題 No.747 循環小数N桁目 Hard
ユーザー tentententen
提出日時 2023-01-10 09:31:18
言語 Java21
(openjdk 21)
結果
AC  
実行時間 139 ms / 2,000 ms
コード長 2,269 bytes
コンパイル時間 2,331 ms
コンパイル使用メモリ 85,232 KB
実行使用メモリ 53,248 KB
最終ジャッジ日時 2023-08-23 09:01:09
合計ジャッジ時間 16,857 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
49,512 KB
testcase_01 AC 41 ms
49,444 KB
testcase_02 AC 41 ms
49,548 KB
testcase_03 AC 42 ms
49,488 KB
testcase_04 AC 43 ms
49,404 KB
testcase_05 AC 41 ms
49,504 KB
testcase_06 AC 43 ms
49,504 KB
testcase_07 AC 42 ms
49,376 KB
testcase_08 AC 42 ms
49,404 KB
testcase_09 AC 42 ms
49,600 KB
testcase_10 AC 41 ms
49,540 KB
testcase_11 AC 43 ms
49,448 KB
testcase_12 AC 42 ms
47,524 KB
testcase_13 AC 43 ms
49,484 KB
testcase_14 AC 42 ms
49,516 KB
testcase_15 AC 44 ms
49,384 KB
testcase_16 AC 43 ms
49,452 KB
testcase_17 AC 43 ms
49,508 KB
testcase_18 AC 42 ms
49,616 KB
testcase_19 AC 42 ms
49,548 KB
testcase_20 AC 43 ms
49,912 KB
testcase_21 AC 44 ms
49,480 KB
testcase_22 AC 43 ms
49,468 KB
testcase_23 AC 43 ms
49,420 KB
testcase_24 AC 45 ms
49,552 KB
testcase_25 AC 43 ms
49,548 KB
testcase_26 AC 43 ms
49,612 KB
testcase_27 AC 43 ms
49,572 KB
testcase_28 AC 44 ms
49,460 KB
testcase_29 AC 41 ms
49,632 KB
testcase_30 AC 41 ms
49,468 KB
testcase_31 AC 43 ms
49,552 KB
testcase_32 AC 42 ms
49,564 KB
testcase_33 AC 89 ms
51,832 KB
testcase_34 AC 58 ms
50,644 KB
testcase_35 AC 57 ms
50,544 KB
testcase_36 AC 58 ms
50,384 KB
testcase_37 AC 53 ms
51,096 KB
testcase_38 AC 64 ms
51,092 KB
testcase_39 AC 61 ms
50,720 KB
testcase_40 AC 95 ms
52,296 KB
testcase_41 AC 87 ms
52,536 KB
testcase_42 AC 87 ms
52,328 KB
testcase_43 AC 63 ms
50,544 KB
testcase_44 AC 85 ms
52,544 KB
testcase_45 AC 88 ms
51,748 KB
testcase_46 AC 81 ms
52,392 KB
testcase_47 AC 88 ms
52,136 KB
testcase_48 AC 63 ms
50,768 KB
testcase_49 AC 64 ms
50,704 KB
testcase_50 AC 63 ms
50,476 KB
testcase_51 AC 60 ms
50,464 KB
testcase_52 AC 58 ms
50,844 KB
testcase_53 AC 139 ms
52,912 KB
testcase_54 AC 112 ms
52,680 KB
testcase_55 AC 113 ms
52,476 KB
testcase_56 AC 105 ms
52,368 KB
testcase_57 AC 60 ms
50,736 KB
testcase_58 AC 136 ms
52,920 KB
testcase_59 AC 74 ms
51,380 KB
testcase_60 AC 114 ms
52,376 KB
testcase_61 AC 86 ms
52,172 KB
testcase_62 AC 98 ms
52,140 KB
testcase_63 AC 87 ms
52,376 KB
testcase_64 AC 60 ms
50,552 KB
testcase_65 AC 51 ms
50,484 KB
testcase_66 AC 73 ms
50,708 KB
testcase_67 AC 59 ms
50,708 KB
testcase_68 AC 86 ms
50,132 KB
testcase_69 AC 82 ms
52,328 KB
testcase_70 AC 62 ms
50,572 KB
testcase_71 AC 58 ms
50,660 KB
testcase_72 AC 64 ms
50,568 KB
testcase_73 AC 88 ms
51,828 KB
testcase_74 AC 86 ms
52,112 KB
testcase_75 AC 60 ms
50,552 KB
testcase_76 AC 66 ms
50,540 KB
testcase_77 AC 64 ms
50,856 KB
testcase_78 AC 85 ms
52,084 KB
testcase_79 AC 71 ms
51,320 KB
testcase_80 AC 83 ms
52,440 KB
testcase_81 AC 59 ms
50,708 KB
testcase_82 AC 62 ms
50,568 KB
testcase_83 AC 58 ms
50,700 KB
testcase_84 AC 83 ms
52,452 KB
testcase_85 AC 84 ms
52,732 KB
testcase_86 AC 79 ms
51,252 KB
testcase_87 AC 84 ms
52,536 KB
testcase_88 AC 64 ms
50,900 KB
testcase_89 AC 65 ms
50,548 KB
testcase_90 AC 80 ms
52,476 KB
testcase_91 AC 87 ms
52,196 KB
testcase_92 AC 64 ms
50,844 KB
testcase_93 AC 82 ms
52,508 KB
testcase_94 AC 101 ms
52,108 KB
testcase_95 AC 111 ms
52,452 KB
testcase_96 AC 107 ms
52,208 KB
testcase_97 AC 110 ms
52,072 KB
testcase_98 AC 133 ms
53,248 KB
testcase_99 AC 121 ms
52,600 KB
testcase_100 AC 112 ms
52,284 KB
testcase_101 AC 88 ms
52,544 KB
testcase_102 AC 81 ms
52,172 KB
testcase_103 AC 90 ms
52,268 KB
testcase_104 AC 95 ms
52,324 KB
testcase_105 AC 86 ms
52,576 KB
testcase_106 AC 89 ms
52,328 KB
testcase_107 AC 86 ms
52,368 KB
testcase_108 AC 86 ms
52,372 KB
testcase_109 AC 94 ms
52,452 KB
testcase_110 AC 91 ms
52,488 KB
testcase_111 AC 93 ms
50,652 KB
testcase_112 AC 91 ms
52,564 KB
testcase_113 AC 95 ms
52,688 KB
testcase_114 AC 90 ms
52,752 KB
testcase_115 AC 91 ms
50,456 KB
testcase_116 AC 90 ms
52,492 KB
testcase_117 AC 86 ms
52,236 KB
testcase_118 AC 94 ms
52,596 KB
testcase_119 AC 90 ms
52,488 KB
testcase_120 AC 94 ms
52,456 KB
testcase_121 AC 91 ms
52,332 KB
testcase_122 AC 87 ms
52,376 KB
testcase_123 AC 87 ms
52,468 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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();
    }
    
}
0