結果

問題 No.6 使いものにならないハッシュ
ユーザー tentententen
提出日時 2020-11-26 18:16:16
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,310 bytes
コンパイル時間 3,085 ms
コンパイル使用メモリ 75,356 KB
実行使用メモリ 59,660 KB
最終ジャッジ日時 2023-10-01 03:28:00
合計ジャッジ時間 10,274 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 116 ms
56,012 KB
testcase_01 AC 116 ms
55,916 KB
testcase_02 AC 160 ms
55,940 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 115 ms
55,788 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.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(i);
		            }
		        }
		        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