結果

問題 No.6 使いものにならないハッシュ
ユーザー mastersatoshimastersatoshi
提出日時 2015-08-01 13:23:36
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,165 bytes
コンパイル時間 2,074 ms
コンパイル使用メモリ 73,884 KB
実行使用メモリ 56,612 KB
最終ジャッジ日時 2023-09-25 00:06:41
合計ジャッジ時間 6,394 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
49,328 KB
testcase_01 WA -
testcase_02 AC 133 ms
54,552 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 43 ms
49,280 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.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;

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

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

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

                if (tmp == d[j]) {
                    break;
                } else {
                    tmpMax = j;
                }
            }

            if (diff <= tmpMax - i) {
                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;
    }
}
0