完善程序一(补全)
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000;
int n;
int vis[MAXN], a[MAXN];
vector<int> ans;
int check(int k) {
int x = n, top = 0;
for (int i = 0; i <= k; i++) vis[i] = 0;
while ( x > 0 ) {
a[++top] = x % k ;
x = x / k;
}
if (top < 2)
return 0;
for (int i = 1; i <= top; i++) {
if (vis[a[i]] == 1 )
return 0;
vis[a[i]] = 1;
}
return 1;
}
int main() {
cin >> n;
for (int i = 2; i <= n; i++) {
if (check(i))
ans.push_back(i);
}
if (ans.empty()) {
cout << -1;
}
for (int i = 0; i < ans.size(); i++)
cout << ans[i] << " ";
return 0;
}
完善程序二(补全)
#include <bits/stdc++.h>
using namespace std;
const int MAXW = 753005;
const int days[13] = {0, 31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int prime[MAXW], cnt;
bool not_prime[MAXW];
void linear_prime(int n) {
--n;
not_prime[0] = not_prime[1] = true;
for(int i = 2; i <= n; i++) {
if(not_prime[i] == false)
prime[++cnt]=i;
for(int j = 1; (j <= cnt) && (i * prime[j] <= n); j++) {
not_prime[i * prime[j]] = 1;
if(i % prime[j] == 0)
break;
}
}
}
bool check(int n) {
return (n % 400 == 0 || (n % 4== 0 && n % 100 != 0));
}
int main() {
linear_prime(MAXW);
int x, y, z, w;
cin >> x >>y >> z;
if(y == 2)
w = check(x) ? 29 : 28;
else
w = days[y];
if(not_prime[x * y * (w - z + 1)])
cout << "unlucky" << endl;
else
cout << "lucky" << endl;
return 0;
}
标签:prime,洛谷,int,31,30,初赛,模拟题,const,top
From: https://blog.csdn.net/weixin_60445850/article/details/141474966