結果

問題 No.6 使いものにならないハッシュ
ユーザー t8m8⛄️t8m8⛄️
提出日時 2016-02-12 00:25:23
言語 Java21
(openjdk 21)
結果
AC  
実行時間 197 ms / 5,000 ms
コード長 1,622 bytes
コンパイル時間 5,376 ms
コンパイル使用メモリ 81,472 KB
実行使用メモリ 58,052 KB
最終ジャッジ日時 2023-10-14 22:57:36
合計ジャッジ時間 11,344 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 133 ms
55,676 KB
testcase_01 AC 134 ms
56,024 KB
testcase_02 AC 197 ms
55,856 KB
testcase_03 AC 155 ms
55,812 KB
testcase_04 AC 160 ms
55,924 KB
testcase_05 AC 165 ms
55,824 KB
testcase_06 AC 167 ms
56,136 KB
testcase_07 AC 164 ms
56,140 KB
testcase_08 AC 165 ms
55,908 KB
testcase_09 AC 168 ms
55,796 KB
testcase_10 AC 136 ms
55,984 KB
testcase_11 AC 155 ms
56,184 KB
testcase_12 AC 168 ms
56,360 KB
testcase_13 AC 159 ms
55,780 KB
testcase_14 AC 161 ms
56,072 KB
testcase_15 AC 166 ms
55,604 KB
testcase_16 AC 169 ms
56,232 KB
testcase_17 AC 167 ms
56,076 KB
testcase_18 AC 165 ms
58,052 KB
testcase_19 AC 163 ms
55,904 KB
testcase_20 AC 164 ms
56,360 KB
testcase_21 AC 144 ms
55,780 KB
testcase_22 AC 165 ms
56,000 KB
testcase_23 AC 166 ms
56,348 KB
testcase_24 AC 170 ms
55,616 KB
testcase_25 AC 166 ms
55,844 KB
testcase_26 AC 193 ms
56,224 KB
testcase_27 AC 164 ms
55,612 KB
testcase_28 AC 165 ms
56,064 KB
testcase_29 AC 167 ms
55,872 KB
testcase_30 AC 166 ms
56,160 KB
testcase_31 AC 166 ms
56,028 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class No006 {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);
	static boolean debug = false;

	static int hash(int p) {
		int sum = 0;
		while (p > 0) {
			sum += p%10;
			p /= 10;
		}
		return sum < 10 ? sum : hash(sum);
	}

	static void solve() {
		int k = in.nextInt();
		int n = in.nextInt();

		BitSet isp = new BitSet();
		isp.set(2, n+1, true);
		for (int i=2; i*i<=n; i=isp.nextSetBit(i+1)) {
			for (int j=i+i; j<=n; j+=i) {
				isp.set(j, false);
			}
		}


		dump(isp);

		ArrayList<Integer> primes = new ArrayList<>();
		for (int i=isp.nextSetBit(k); i>=0; i=isp.nextSetBit(i+1)) {
			primes.add(i);
		}

		dump(primes);

		int m = primes.size();
		int l = 0, max = 0;
		int ans = -1;
		BitSet mask = new BitSet();
		ArrayList<Integer> hashes = new ArrayList<>();
		for (int r=0; r<m; r++) {
			int h = hash(primes.get(r));
			hashes.add(h);
			if (mask.get(h)) {
				while (h != hashes.get(l)) {
					mask.set(hashes.get(l), false);
					l++;
				}
				l++;
			} else {
				mask.set(h);
			}
			int x = mask.cardinality();

			if (max <= x) {
				max = x;
				ans = l;
			}
		}

		out.println(primes.get(ans));
	}

	public static void main(String[] args) {
		debug = args.length > 0;
		long start = System.currentTimeMillis();

		solve();
		out.flush();

		long end = System.currentTimeMillis();
		dump((end-start) + "ms");
		in.close();
		out.close();
	}

	static void dump(Object... o) { if (debug) System.err.println(Arrays.deepToString(o)); }
}
0