結果

問題 No.385 カップ麺生活
コンテスト
ユーザー testestest
提出日時 2016-07-01 23:16:45
言語 C90
(gcc 12.4.0)
コンパイル:
gcc-12 -O2 -std=c90 -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 562 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 177 ms
コンパイル使用メモリ 30,660 KB
最終ジャッジ日時 2026-02-23 21:44:22
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 32
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c:2:1: warning: data definition has no type or storage class
    2 | i,m,n;a[30];
      | ^
main.c:2:7: warning: data definition has no type or storage class
    2 | i,m,n;a[30];
      |       ^
main.c:3:1: warning: data definition has no type or storage class
    3 | prime[2000]={2,3},s=2;
      | ^~~~~
main.c:4:1: warning: data definition has no type or storage class
    4 | ma[20010];
      | ^~
main.c: In function ‘main’:
main.c:19:9: warning: incompatible implicit declaration of built-in function ‘scanf’ [-Wbuiltin-declaration-mismatch]
   19 |         scanf("%d %d",&m,&n);
      |         ^~~~~
main.c:1:1: note: include ‘<stdio.h>’ or provide a declaration of ‘scanf’
  +++ |+#include <stdio.h>
    1 | #define max(p,q)(p>q?p:q)
main.c:26:9: warning: incompatible implicit declaration of built-in function ‘printf’ [-Wbuiltin-declaration-mismatch]
   26 |         printf("%lld",ans+m/a[0]);
      |         ^~~~~~
main.c:26:9: note: include ‘<stdio.h>’ or provide a declaration of ‘printf’

ソースコード

diff #
raw source code

#define max(p,q)(p>q?p:q)
i,m,n;a[30];
prime[2000]={2,3},s=2;
ma[20010];

x(int*a,int*b){return*a-*b;}
makeprime(){
	int i,n;
	for(n=5;n<10000;n+=2){
		for(i=3;i*i<=n;i+=2)if(n%i==0)break;
		if(n%i)prime[s++]=n;
	}
	prime[s]=1e6;
}
main(){
	int i,j;
	long long ans=0;
	makeprime();
	scanf("%d %d",&m,&n);
	for(i=0;~scanf("%d",a+i);i++);
	a[i]=1e9;
	qsort(a,n,4,x);
	ma[0]=1;
	for(i=0;i<10000;i++)for(j=0;j<n;j++)if(ma[i])ma[i+a[j]]=max(ma[i]+1,ma[i+a[j]]);
	for(i=0;prime[i]<m;i++)if(ma[m-prime[i]])ans+=ma[m-prime[i]]-1;
	printf("%lld",ans+m/a[0]);
	return 0;
}
0