// 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=2263 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[1] = 2, sz = 2; for (i = 3; i <= n; i+=2) if (!prime[i]) tbl[sz++] = i; } int main() { int i, j, k, N; scanf("%d", &N); sieve(N); a[N] = 1; for (i = N; i >= 0; i--) if (a[i]) { for (j = b[i]+1; (k = i-tbl[j]) >= 0; j++) { if (a[i]+1 > a[k] || (a[i]+1 == a[k] && b[k] > j)) a[k] = a[i]+1, b[k] = j; } } if (a[0]) printf("%d\n", a[0]-1); else puts("-1"); return 0; }