結果

問題 No.6 使いものにならないハッシュ
ユーザー t8m8⛄️t8m8⛄️
提出日時 2016-02-12 00:24:26
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,620 bytes
コンパイル時間 6,255 ms
コンパイル使用メモリ 86,960 KB
実行使用メモリ 58,288 KB
最終ジャッジ日時 2023-10-22 02:24:09
合計ジャッジ時間 13,632 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 147 ms
57,744 KB
testcase_01 AC 146 ms
57,824 KB
testcase_02 AC 181 ms
55,912 KB
testcase_03 AC 168 ms
57,840 KB
testcase_04 AC 165 ms
57,104 KB
testcase_05 AC 181 ms
57,568 KB
testcase_06 AC 180 ms
57,820 KB
testcase_07 AC 175 ms
57,796 KB
testcase_08 AC 171 ms
57,120 KB
testcase_09 AC 162 ms
57,232 KB
testcase_10 AC 149 ms
57,812 KB
testcase_11 WA -
testcase_12 AC 179 ms
55,904 KB
testcase_13 AC 171 ms
57,904 KB
testcase_14 WA -
testcase_15 AC 176 ms
57,816 KB
testcase_16 WA -
testcase_17 AC 179 ms
57,836 KB
testcase_18 AC 180 ms
57,796 KB
testcase_19 WA -
testcase_20 AC 176 ms
57,552 KB
testcase_21 AC 159 ms
57,904 KB
testcase_22 WA -
testcase_23 AC 183 ms
57,864 KB
testcase_24 AC 178 ms
57,836 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 180 ms
57,856 KB
testcase_28 AC 175 ms
57,884 KB
testcase_29 WA -
testcase_30 AC 185 ms
57,848 KB
testcase_31 AC 184 ms
57,816 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