結果

問題 No.6 使いものにならないハッシュ
ユーザー tentententen
提出日時 2020-11-26 18:30:55
言語 Java21
(openjdk 21)
結果
AC  
実行時間 174 ms / 5,000 ms
コード長 1,316 bytes
コンパイル時間 3,946 ms
コンパイル使用メモリ 75,124 KB
実行使用メモリ 58,736 KB
最終ジャッジ日時 2023-10-14 23:28:15
合計ジャッジ時間 8,452 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
56,024 KB
testcase_01 AC 119 ms
55,496 KB
testcase_02 AC 163 ms
56,456 KB
testcase_03 AC 153 ms
56,748 KB
testcase_04 AC 152 ms
55,688 KB
testcase_05 AC 160 ms
56,720 KB
testcase_06 AC 167 ms
56,056 KB
testcase_07 AC 160 ms
56,624 KB
testcase_08 AC 165 ms
54,696 KB
testcase_09 AC 134 ms
56,392 KB
testcase_10 AC 117 ms
55,724 KB
testcase_11 AC 148 ms
56,644 KB
testcase_12 AC 166 ms
57,504 KB
testcase_13 AC 137 ms
55,956 KB
testcase_14 AC 138 ms
55,988 KB
testcase_15 AC 168 ms
58,736 KB
testcase_16 AC 159 ms
55,864 KB
testcase_17 AC 174 ms
56,732 KB
testcase_18 AC 172 ms
57,400 KB
testcase_19 AC 174 ms
56,688 KB
testcase_20 AC 169 ms
56,888 KB
testcase_21 AC 128 ms
55,988 KB
testcase_22 AC 172 ms
57,032 KB
testcase_23 AC 173 ms
56,628 KB
testcase_24 AC 173 ms
56,704 KB
testcase_25 AC 166 ms
55,800 KB
testcase_26 AC 168 ms
56,452 KB
testcase_27 AC 168 ms
57,160 KB
testcase_28 AC 168 ms
55,788 KB
testcase_29 AC 160 ms
56,216 KB
testcase_30 AC 164 ms
57,280 KB
testcase_31 AC 171 ms
56,700 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		int n = sc.nextInt();
		HashSet<Integer> used = new HashSet<>();
		ArrayDeque<Integer> deq = new ArrayDeque<>();
		int max = 0;
		int ans = 0;
		boolean[] isNotPrime = new boolean[n + 1];
		for (int i = 2; i <= n; i++) {
		    if (!isNotPrime[i]) {
    	        for (int j = 2; j * i <= n; j++) {
    	            isNotPrime[j * i] = true;
    	        }
    	        if (i < k) {
    	            continue;
    	        }
		        int h = hash(i);
		        if (used.contains(h)) {
		            while (deq.size() > 0) {
		                int x = deq.poll();
		                if (hash(x) == h) {
		                    break;
		                }
		                used.remove(hash(x));
		            }
		        }
		        used.add(h);
    	        deq.add(i);
    	        if (max <= deq.size()) {
    	            max = deq.size();
    	            ans = deq.getFirst();
    	        }
		    }
		}
        System.out.println(ans);
	}
	
	static int hash(int x) {
	    if (x < 10) {
	        return x;
	    } else {
	        int sum = 0;
	        while (x > 0) {
	            sum += x % 10;
	            x /= 10;
	        }
	        return hash(sum);
	    }
	}
}

0