我的原来70分代码是这样的:
#include <bits/stdc++.h>
using namespace std;
int t, x;
int cnt = 0;
int ans[10000001];
bool vis[10000001];
inline bool check(int x)
{
int t = x;
while(t)
{
if(t % 10 == 7) return 1;
t /= 10;
}
return 0;
}
inline void init()
{
for(int i = 1; i <= 10000000; i++)
{
if(vis[i]) continue;
if(check(i))
{
vis[i] = 1;
for(int j = i << 1; j <= 10000000; j += i)
vis[j] = 1;
continue;
}
ans[cnt] = i;
cnt = i;
}
}
int main()
{
cin >> t;
init();
while(t--)
{
cin >> x;
if(vis[x]) cout << -1 << endl;
else cout << ans[x] << endl;
}
return 0;
}
但为什么改一个东西就100了呢?
#include <bits/stdc++.h>
using namespace std;
int t, x;
int cnt = 0;
int ans[10000101]; //这里
bool vis[10000101]; //这里
inline bool check(int x)
{
int t = x;
while(t)
{
if(t % 10 == 7) return 1;
t /= 10;
}
return 0;
}
inline void init()
{
for(int i = 1; i <= 10000090; i++) //i的范围
{
if(vis[i]) continue;
if(check(i))
{
vis[i] = 1;
for(int j = i << 1; j <= 10000090; j += i) //j的范围
vis[j] = 1;
continue;
}
ans[cnt] = i;
cnt = i;
}
}
int main()
{
cin >> t;
init();
while(t--)
{
cin >> x;
if(vis[x]) cout << -1 << endl;
else cout << ans[x] << endl;
}
return 0;
}