結果

問題 No.6 使いものにならないハッシュ
ユーザー DAZYDAZY
提出日時 2017-05-29 01:28:50
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,820 bytes
コンパイル時間 4,110 ms
コンパイル使用メモリ 77,576 KB
実行使用メモリ 58,084 KB
最終ジャッジ日時 2023-10-21 14:54:04
合計ジャッジ時間 27,704 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 132 ms
57,184 KB
testcase_02 AC 1,475 ms
57,532 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 134 ms
57,500 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
権限があれば一括ダウンロードができます

ソースコード

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 (ans == 0) ans = tmp2;
        System.out.println(ans);
    }
}
0