結果

問題 No.6 使いものにならないハッシュ
ユーザー bal4ubal4u
提出日時 2019-04-07 20:28:52
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,328 bytes
コンパイル時間 356 ms
コンパイル使用メモリ 29,200 KB
実行使用メモリ 4,368 KB
最終ジャッジ日時 2023-10-14 23:16:21
合計ジャッジ時間 1,540 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

// yukicoder: No.6 使いものにならないハッシュ
// 2019.4.7 bal4u
// 素数表、バカ計算

#include <stdio.h>
#include <string.h>

#define MAX  200002
#define SQRT 447
char notPrime[MAX] = { 1,1,0,0,1 };			// zero: if prime
int ptbl[18000] = { 2, 3, 5, 7, 11, 13 }; int sz;  // 17984
char a[18000];
typedef struct { int fr, to; char n; } T;
T t[18000];

void sieve()
{
	int i, j;
	for (i = 3; i <= SQRT; i += 2) {
		if (!notPrime[i]) {
			for (j = i * i; j < MAX; j += i) notPrime[j] = 1;
		}
	}
	sz = 1; for (i = 3; i <= MAX; i += 2) if (!notPrime[i]) ptbl[sz++] = i;
}

int calc(int n)
{
	int s;
	if (n < 10) return n;
	s = 0; while (n) s += n % 10, n /= 10;
	return calc(s);
}

int upper_bound(int x)
{
	int m, l = 0, r = sz;
	while (l < r) {
		m = (l + r) >> 1;
		if (ptbl[m] <= x) l = m + 1; else r = m;
	}
	return l - 1;
}

int getLen(int fr, int tid)
{
	int i, j, ans, len;
	char f[10];

	len = ans = 0;
	for (i = tid; ptbl[i] >= fr; i--) {
		memset(f, 0, 10);
		f[a[i]] = 1;
		for (j = i - 1; ptbl[j] >= fr; j--) {
			if (f[a[j]]) break;
			f[a[j]] = 1;
		}
		if (i - j > len) len = i - j, ans = ptbl[j + 1];
	}
	return ans;
}

int main()
{
	int i, k, K, N;

	sieve();
	for (i = 0; i < sz; i++) a[i] = calc(ptbl[i]);
	scanf("%d%d", &K, &N);
	k = upper_bound(N);
	printf("%d\n", getLen(K, k));
	return 0;
}
0