結果
| 問題 | No.6 使いものにならないハッシュ | 
| コンテスト | |
| ユーザー |  mastersatoshi | 
| 提出日時 | 2015-08-01 14:47:12 | 
| 言語 | Java (openjdk 23) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 121 ms / 5,000 ms | 
| コード長 | 1,977 bytes | 
| コンパイル時間 | 2,176 ms | 
| コンパイル使用メモリ | 78,156 KB | 
| 実行使用メモリ | 44,228 KB | 
| 最終ジャッジ日時 | 2024-09-16 16:28:33 | 
| 合計ジャッジ時間 | 6,351 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 32 | 
ソースコード
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);
    }
}
            
            
            
        