結果

問題 No.6 使いものにならないハッシュ
ユーザー bal4ubal4u
提出日時 2021-08-13 09:04:38
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 899 bytes
コンパイル時間 1,290 ms
コンパイル使用メモリ 33,280 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-10 15:17:22
合計ジャッジ時間 1,785 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 1 ms
5,376 KB
testcase_21 AC 1 ms
5,376 KB
testcase_22 AC 1 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 1 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 1 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// yukicoder: 6. 使いものにならないハッシュ
// 2021.8.13

#include <stdio.h>
#include <math.h>

#define MAX  200005
char cn[MAX] = { 1,1,0,0,1 };			// 合成数
int  a[MAX], hash[MAX], sz;

void sieve(int max) {
	int i, j;
	int sq = sqrt(max);
//	for (i = 2; i <= max; i+=2) cn[i] = 1;
	for (i = 3; i <= sq; i += 2) if (!cn[i]) {
		for (j = i*i; j <= max; j += i) cn[j] = 1;
	}
}

int main()
{
	int i, k, t, K, N;
	int ans, w;

	scanf("%d%d", &K, &N);
	sieve(N);
	if (K <= 2) a[0] = hash[0] = 2, sz = 1, i = 3;
	else i = (K/2)*2+1;
	for ( ; i <= N; i+=2) if (!cn[i]) {
		a[sz] = i;
		k = i; while (k >= 10) {
			t = 0; while (k) t += k % 10, k /= 10;
			k = t;
		}
		hash[sz++] = k;
	}

	w = 0; for (i = 0; i < sz; ++i) {
		t = 1<<hash[i];
		k = i+1; while (k < sz && !(t & (1<<hash[k]))) t |= 1<<hash[k++];
		if (k-i+1 >= w) w = k-i+1, ans = a[i];
	}
	printf("%d\n", ans);
	return 0;
}
0