Codeforces Round #696 (Div. 2) B. Different Divisors
Codeforces Round #696 (Div. 2) B. Different Divisors
原题链接)
题目分析
找规律,最后会发现是间隔大于等于d的两个质数的积。可以先打表,然后再用二分查找找到对应的下标,输出答案即可。
AC代码
#include<bits/stdc++.h>
using namespace std;
#define io ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
const int N = 1e5 + 1000;
bool isnp[N];
int k ;
int prime[N];
void init(){
for (int i = 2; i <= N; i++){
if (!isnp[i]) prime[k++] = i;
for (int j = 0; j < N; j++){
if (prime[j] * i > N) break;
isnp[prime[j] * i] = 1;
if (i % prime[j] == 0) break;
}
}
}
int t, n, m;
int main(){
io;
init();
cin >> t;
while(t--){
cin >> n;
int a = lower_bound(prime, prime + k, n + 1) - prime;
int b = lower_bound(prime + a, prime + k, n + prime[a]) - prime;
long long ans = prime[a] * prime[b];
cout << ans << endl;
}
return 0;
}