結果

問題 No.458 異なる素数の和
ユーザー butsurizukibutsurizuki
提出日時 2016-12-09 00:15:06
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 41 ms / 2,000 ms
コード長 395 bytes
コンパイル時間 204 ms
コンパイル使用メモリ 24,704 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-18 14:51:23
合計ジャッジ時間 2,824 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<stdio.h>

int main(void){
	int p[32768]={0},i,j,n,m[32768]={0};
	for(i = 2;i <= 185;i++){if(!p[i]){for(j = 2*i;j <= 20000;j+=i){p[j]=1;}}}
	for(i = 2;i <= 20000;i++){
		if(!p[i]){
			for(j = 25000-i;j >= 0;j--){
				if(j == 0 || m[j] != 0){
					if(m[j] + 1 > m[j+i]){m[j+i] = m[j]+1;}
				}
			}
		}
	}
	scanf("%d",&n);
	if(m[n]){printf("%d\n",m[n]);}else{printf("-1\n");}
	return 0;
}
0