結果
| 問題 |
No.6 使いものにならないハッシュ
|
| コンテスト | |
| ユーザー |
mastersatoshi
|
| 提出日時 | 2015-08-01 13:39:36 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,416 bytes |
| コンパイル時間 | 2,474 ms |
| コンパイル使用メモリ | 78,172 KB |
| 実行使用メモリ | 58,096 KB |
| 最終ジャッジ日時 | 2024-07-18 00:26:16 |
| 合計ジャッジ時間 | 7,089 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 5 WA * 27 |
ソースコード
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 diff = Integer.MIN_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 tmpCount = 0;
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 {
tmpCount++;
tmpMax = j;
map.put(d[j], j);
}
}
if (count <= tmpCount && diff <= tmpMax - i) {
count = tmpCount;
diff = tmpMax - i;
min = i;
}
}
System.out.println(min);
}
private static int change(int source) {
char[] c = Integer.toString(source).toCharArray();
while (c.length != 1) {
source = 0;
if (c.length > 1) {
for (int i = 0; i < c.length; i++) {
source += Integer.parseInt(String.valueOf(c[i]));
}
} else {
source += Integer.parseInt(String.valueOf(c));
break;
}
c = Integer.toString(source).toCharArray();
}
return source;
}
}
mastersatoshi