結果

問題 No.6 使いものにならないハッシュ
ユーザー mastersatoshimastersatoshi
提出日時 2015-08-01 14:47:12
言語 Java21
(openjdk 21)
結果
AC  
実行時間 106 ms / 5,000 ms
コード長 1,977 bytes
コンパイル時間 4,892 ms
コンパイル使用メモリ 74,812 KB
実行使用メモリ 55,928 KB
最終ジャッジ日時 2023-10-14 22:54:08
合計ジャッジ時間 5,924 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
49,104 KB
testcase_01 AC 39 ms
49,108 KB
testcase_02 AC 105 ms
55,208 KB
testcase_03 AC 62 ms
51,448 KB
testcase_04 AC 80 ms
52,376 KB
testcase_05 AC 78 ms
54,576 KB
testcase_06 AC 90 ms
55,176 KB
testcase_07 AC 90 ms
54,552 KB
testcase_08 AC 89 ms
54,732 KB
testcase_09 AC 79 ms
53,388 KB
testcase_10 AC 40 ms
49,344 KB
testcase_11 AC 78 ms
51,988 KB
testcase_12 AC 101 ms
55,740 KB
testcase_13 AC 73 ms
52,080 KB
testcase_14 AC 83 ms
53,180 KB
testcase_15 AC 97 ms
54,816 KB
testcase_16 AC 88 ms
54,796 KB
testcase_17 AC 94 ms
54,724 KB
testcase_18 AC 106 ms
55,076 KB
testcase_19 AC 102 ms
55,296 KB
testcase_20 AC 99 ms
55,092 KB
testcase_21 AC 57 ms
51,096 KB
testcase_22 AC 95 ms
55,288 KB
testcase_23 AC 98 ms
55,480 KB
testcase_24 AC 96 ms
55,112 KB
testcase_25 AC 76 ms
53,348 KB
testcase_26 AC 97 ms
55,048 KB
testcase_27 AC 97 ms
54,952 KB
testcase_28 AC 93 ms
55,556 KB
testcase_29 AC 104 ms
55,924 KB
testcase_30 AC 94 ms
55,304 KB
testcase_31 AC 99 ms
55,928 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) throws Exception {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int K = Integer.parseInt(br.readLine());
        int N = Integer.parseInt(br.readLine());

        int sc = (int) Math.sqrt(N);

        int[] d = new int[N + 1];

        d[0] = -1;
        d[1] = -1;

        for (int i = 2; i <= sc; i++) {
            if (d[i] != 0) {
                continue;
            }
            for (int j = i; j < N; j++) {
                int dest = i * j;
                if (dest > d.length - 1) {
                    break;
                }
                d[i * j] = -1;
            }
        }

        int tmpMax = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;

        int count = 0;

        for (int i = K; i <= N; i++) {
            if (d[i] == -1) {
                continue;
            }

            if (d[i] == 0) {
                d[i] = change(i);
            }

            HashMap<Integer, Integer> map = new HashMap();
            map.put(d[i], i);

            int j = i + 1;
            for (; j <= N; j++) {
                if (d[j] == -1) {
                    continue;
                } else if (d[j] == 0) {
                    d[j] = change(j);
                }

                if (map.containsKey(d[j])) {
                    break;
                } else {
                    tmpMax = j;
                    map.put(d[j], j);
                }
            }

            if (count <= map.size()) {
                count = map.size();
                min = i;
            }
        }

        System.out.println(min);
    }

    private static int change(int source) {

        if (source < 10) {
            return source;
        }
        int sum = 0;
        while (0 < source) {
            sum += source % 10;
            source /= 10;
        }
        return change(sum);
    }
}
0