結果

問題 No.6 使いものにならないハッシュ
ユーザー FF256grhyFF256grhy
提出日時 2015-05-11 11:37:30
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 1,119 bytes
コンパイル時間 202 ms
コンパイル使用メモリ 26,232 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-14 22:52:10
合計ジャッジ時間 1,590 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 3 ms
4,348 KB
testcase_02 AC 3 ms
4,348 KB
testcase_03 AC 3 ms
4,348 KB
testcase_04 AC 3 ms
4,352 KB
testcase_05 AC 3 ms
4,352 KB
testcase_06 AC 3 ms
4,348 KB
testcase_07 AC 3 ms
4,348 KB
testcase_08 AC 3 ms
4,348 KB
testcase_09 AC 3 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 3 ms
4,352 KB
testcase_12 AC 3 ms
4,352 KB
testcase_13 AC 3 ms
4,352 KB
testcase_14 AC 3 ms
4,352 KB
testcase_15 AC 3 ms
4,348 KB
testcase_16 AC 3 ms
4,348 KB
testcase_17 AC 3 ms
4,348 KB
testcase_18 AC 3 ms
4,348 KB
testcase_19 AC 3 ms
4,348 KB
testcase_20 AC 3 ms
4,352 KB
testcase_21 AC 3 ms
4,348 KB
testcase_22 AC 3 ms
4,352 KB
testcase_23 AC 3 ms
4,348 KB
testcase_24 AC 4 ms
4,348 KB
testcase_25 AC 3 ms
4,348 KB
testcase_26 AC 3 ms
4,348 KB
testcase_27 AC 4 ms
4,348 KB
testcase_28 AC 3 ms
4,348 KB
testcase_29 AC 3 ms
4,352 KB
testcase_30 AC 3 ms
4,348 KB
testcase_31 AC 4 ms
4,352 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int search()’:
main.cpp:54:9: warning: ‘max_p’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  return max_p;
         ^~~~~

ソースコード

diff #

#include <stdio.h>

#define MAX 200000

void make_prime_list();
int search();
//int hash(int);

int m, n;
int table[MAX + 1]; // 0, 1番目は無視
int prime[MAX], p_cnt;

int main(void) {
	scanf("%d%d", &m, &n);
	make_prime_list();
	printf("%d\n", search());
	return 0;
}

void make_prime_list() {
	int i;
	for(i = 2; i <= n; i++) {
		if(table[i] == 0) { // 0のときにiは素数
			if(m <= i) {
				prime[p_cnt] = i;
				p_cnt++;
			}
			int multi = 2 * i;
			while(multi <= MAX) {
				table[multi] = 1;
				multi += i;
			}
		}
	}
	return;
}

int search() {
	int memo[9], max_l = 0, max_p;
	int i, j;
	for(i = p_cnt - 1; 0 <= i; i--) {
		for(j = 0; j < 9; j++) { memo[j] = 0; }
		j = i;
		while(j < p_cnt) {
			if( memo[ prime[j] % 9 ] ) { break; }
			memo[ prime[j] % 9 ]++;
			j++;
		}
		if(max_l < j - i) {
			max_l = j - i;
			max_p = prime[i];
		}
	}
	return max_p;
}

/* よく考えたらいらなかったやつ (hash(x) は x%9 と同一視できる(0を9とみなせばよい))
int hash(int x) {
	if(x < 10) { return x; }
	int sum = 0;
	while(x) {
		sum += x % 10;
		x /= 10;
	}
	return hash(sum);
}
*/
0