#include #include #define MAX(a,b) ((a)<(b)?(b):(a)) void run(void){ int n; scanf("%d",&n); if(n<=2){ printf("%d\n",n==1?-1:1); return; } char *isPrime=(char *)calloc(n+1,sizeof(char)); int i; isPrime[2]=1; for(i=3;i<=n;i++){ isPrime[i]=i%2; } for(i=3;i*i<=n;i+=2){ if(isPrime[i]){ int j; for(j=i*i;j<=n;j+=2*i){ isPrime[j]=0; } } } int *ans=(int *)calloc(n+1,sizeof(int)); ans[2]=1; int up=2; for(i=3;i<=n;i+=2){ if(isPrime[i]){ int j; for(j=(i+up)>n?n:(i+up);j>i;j--){ ans[j]=MAX(ans[j],(ans[j-i]>0)*(ans[j-i]+1)); } ans[i]=MAX(ans[i],1); up+=i; } } printf("%d\n",ans[n]==0?-1:ans[n]); return; } int main(void){ run(); return 0; }