// yukicoder: No.458 異なる素数の和 // 2019.4.23 bal4u #include #include #include #define MAX 20000 #define SQRT 141 // sqrt(MAX) char prime[MAX+2] = {1,1,0,0,1,0,1,0,1,1,0}; // 0:素数 int tbl[2300], sz; // sz=2262 int a[MAX+2]; int b[MAX+2]; void sieve(int n) { int i, j, b; b = (int)sqrt((double)n); for (i = 3; i <= b; i += 2) { for (j = i*i; j <= n; j += i) prime[j] = 1; } tbl[0] = 2, sz = 1; for (i = 3; i <= MAX; i+=2) if (!prime[i]) tbl[sz++] = i; } int main() { int i, j, N; scanf("%d", &N); sieve(N); a[N] = 1; memset(b, -1, sizeof(b)); for (i = N; i >= 0; i--) if (a[i]) { for (j = b[i]+1; j < sz; j++) { if (i-tbl[j] >= 0) a[i-tbl[j]] = a[i]+1, b[i-tbl[j]] = j; } } if (a[0] == 0) puts("-1"); else printf("%d\n", a[0]-1); return 0; }