/* -*- coding: utf-8 -*- * * 1058.cc: No.1058 素敵な数 - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const int MAX_N = 10; const int MAX_M = MAX_N * MAX_N; const int MAX_P = 100200; /* typedef */ typedef long long ll; /* global variables */ bool primes[MAX_P + 1]; int pnums[MAX_P]; ll as[MAX_M]; /* subroutines */ int gen_primes(int maxp, int pnums[]) { memset(primes, true, sizeof(primes)); primes[0] = primes[1] = false; int p, pn = 0; for (p = 2; p * p <= maxp; p++) if (primes[p]) { pnums[pn++] = p; for (int q = p * p; q <= maxp; q += p) primes[q] = false; } for (; p <= maxp; p++) if (primes[p]) pnums[pn++] = p; return pn; } /* main */ int main() { int pn = gen_primes(MAX_P, pnums); //printf("pn=%d\n", pn); int k = upper_bound(pnums, pnums + pn, 100000) - pnums; //for (int i = k; i < pn; i++) printf("%d ", pnums[i]); putchar('\n'); int n; scanf("%d", &n); if (n == 1) { puts("1"); return 0; } n--; int m = 0; for (int i = 0; i < n; i++) for (int j = i; j < n; j++) as[m++] = (ll)pnums[k + i] * pnums[k + j]; sort(as, as + m); printf("%lld\n", as[n - 1]); return 0; }