// yukicoder: No.811 約数の個数の最大化 // 2019.6.15 bal4u #include #define MAX 100000 #define PMAX 65 int ptbl[PMAX+2] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313 }; int base[PMAX], power[PMAX], sz; int f[MAX+2], d[MAX+2]; int main() { int i, j, k, n, N, K, max, idx; scanf("%d%d", &N, &K); // Nの素因数分解 n = N; for (i = 0; n > 1 && i < PMAX; i++) { k = ptbl[i]; if (n % k == 0) { base[sz] = k; do n /= k, power[sz]++; while (n % k == 0); sz++; } } if (n > 1) base[sz] = n, power[sz++] = 1; // 共通素因数 for (i = 0; i < sz; i++) { j = base[i]; for (k = 0; k < power[i]; k++) { for (n = j; n <= N; n += j) f[n]++; j *= base[i]; } } // 約数の数 max = 0; for (i = 2; i < N; i++) d[i] = 2; for (i = 2; i <= N/2; i++) { for (j = i << 1; j < N; j += i) { if (++d[j] > max && f[j] >= K) max = d[j], idx = j; } } printf("%d\n", idx); return 0; }