I_love_zz @ 2024-09-24 21:21:52
本题有部分是直接ctrl+c搞到的
所以不代表我这个辣鸡的实力
我很菜的
所以求大佬给出修改建议!!
感谢!!!
#include <iostream>
#include<algorithm>
#include<vector>
#include<math.h>
using namespace std;
bool isp(int num) {
if (num < 0) {
return false;
}
int originalNum = num;
int reversedNum = 0;
while (num > 0) {
reversedNum = reversedNum * 10 + num % 10;
num /= 10;
}
return originalNum == reversedNum;
}
std::vector<bool> sieveOfEratosthenes(int n) {
std::vector<bool> isPrime(n+1, true);
isPrime[0] = isPrime[1] = false;
int sqrtN = sqrt(n);
for (int i = 2; i <= sqrtN; i++) {
if (isPrime[i]) {
for (int j = i*i; j <= n; j += i) {
isPrime[j] = false;
}
}
}
return isPrime;
}
bool isPrime(int n) {
std::vector<bool> primes = sieveOfEratosthenes(n);
return primes[n];
}
int main() {
int a = 0, b = 0;
cin >> a >> b;
for (int i = a; i <= b; i++) {
if (i % 2 != 0) {
if (isp(i)&&isPrime(i)) {
printf("%d\n", i);
}
}
}
return 0;
}
by Sheep_YCH @ 2024-09-24 21:24:56
@I_love_zz
#include <iostream>
using namespace std;
bool z(long long a) {
for (int i = 2; i * i <= a; i++) {
if (a % i == 0) {
return false;
}
}
return true;
}
int main() {
long long m, n;
cin >> n >> m;
if(n == 1) n += 2;
if(n > 1 && n < 3) cout << 2 << endl;
for (long long i = n; i <= m; i++) {
if(i % 2 != 0) {
long long h = 0, k = i;
while (k > 0) {
h = h * 10 + k % 10;
k /= 10;
}
if(h == i && h % 2 == 1) {
if (z(i))
cout << i << endl;
}
}
}
return 0;
}
这道题的主旨思想其实是这样的
by Sheep_YCH @ 2024-09-24 21:25:45
@I_love_zz
其实AI做题大部分时候还不如人类qwq
by I_love_zz @ 2024-09-24 21:39:04
@Sheep_YCH
那倒是,脑子会做手不会打程序
感谢!!
by zhouzihang1 @ 2024-09-24 21:39:58
@I_love_zz 你猜“说明/提示”里的是什么