結果

問題 No.6 使いものにならないハッシュ
ユーザー DAZYDAZY
提出日時 2017-05-29 01:38:10
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,549 ms / 5,000 ms
コード長 1,825 bytes
コンパイル時間 5,318 ms
コンパイル使用メモリ 78,684 KB
実行使用メモリ 56,076 KB
最終ジャッジ日時 2023-10-14 23:07:08
合計ジャッジ時間 28,217 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
55,688 KB
testcase_01 AC 127 ms
55,736 KB
testcase_02 AC 1,549 ms
55,416 KB
testcase_03 AC 190 ms
55,476 KB
testcase_04 AC 288 ms
55,648 KB
testcase_05 AC 269 ms
55,688 KB
testcase_06 AC 724 ms
55,484 KB
testcase_07 AC 507 ms
53,572 KB
testcase_08 AC 708 ms
55,652 KB
testcase_09 AC 450 ms
55,760 KB
testcase_10 AC 129 ms
55,432 KB
testcase_11 AC 201 ms
55,712 KB
testcase_12 AC 783 ms
55,720 KB
testcase_13 AC 297 ms
55,828 KB
testcase_14 AC 434 ms
55,920 KB
testcase_15 AC 599 ms
55,732 KB
testcase_16 AC 698 ms
55,620 KB
testcase_17 AC 1,252 ms
55,636 KB
testcase_18 AC 1,391 ms
55,672 KB
testcase_19 AC 1,200 ms
55,920 KB
testcase_20 AC 868 ms
55,616 KB
testcase_21 AC 153 ms
55,624 KB
testcase_22 AC 1,057 ms
56,076 KB
testcase_23 AC 778 ms
55,536 KB
testcase_24 AC 934 ms
55,436 KB
testcase_25 AC 543 ms
55,644 KB
testcase_26 AC 1,230 ms
55,592 KB
testcase_27 AC 964 ms
55,756 KB
testcase_28 AC 423 ms
55,488 KB
testcase_29 AC 1,256 ms
55,748 KB
testcase_30 AC 974 ms
55,692 KB
testcase_31 AC 970 ms
55,716 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class No6 {
    public static boolean checkPrime (int n) {
        boolean b = true;
        if (n==2 || n==3 || n==5) ;
        else if ((n & 1)==0 || n==1) b = false;
        else {
            for (int i = 3; i < n/2; i+=2) {
                if (n % i==0) {
                    b = false;
                    break;
                }
            }
        }
        return b;
    }
    public static int sumEachbit (int n) {
        int sum;
        while (n > 9) {
            sum = 0;
            for (; n > 0;) {
                sum += n%10;
                n /= 10;
            }
            n = sum;
        }
        return n;
    }
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int K = scan.nextInt();
        int N = scan.nextInt();
        int[] S = new int[N+1];
        int check[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
        int ans = 0, max = 0, tmp1 = 0, tmp2 = 0, tmp3 = 0;
        for (int i = K; i <= N; i++) {
            if (checkPrime(i)) {
                S[i] = i;
                if (S[i] > 9) S[i] = sumEachbit(i);
            } else S[i] = -1;
        }
        for (int i = K; i <= N; i++) {
            if (S[i] == -1);
            else {
                if (tmp1 == 1) tmp3 = i;
                if (check[S[i]] == 0) {
                    if (tmp1 == 0) tmp2 = i;
                    tmp1++;
                    check[S[i]] = 1;
                } else {
                    if (tmp1 >= max) {
                        max = tmp1;
                        ans = tmp2;
                    }
                    tmp1 = 0;
                    Arrays.fill(check, 0);
                    i = tmp3 - 1;
                }
            }
        }
        if (tmp1 >= max) ans = tmp2;
        System.out.println(ans);
    }
}
0