素数对
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
bool check(int x)
{
int t = sqrt(x);
for(int i = 2; i <= t; i++)
{
if( x % i == 0) return 0;
}
return 1;
}
int main() {
int n;
bool flag = 0;
cin >> n;
for(int i = 3; i<= n-2; i++)
{
if(check(i) == 1 && check(i+2) == 1)
printf("%d %d\n", i, i+2);
flag = 1;
}
if(flag == 0) cout << "empty";
return 0;
}
哥德巴赫猜想
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
bool check(int x)
{
int t = sqrt(x);
for(int i = 2; i <= t; i++)
{
if( x % i == 0) return 0;
}
return 1;
}
int main() {
int n;
cin >> n;
for(int i = 3; i<= n/2; i++)
{
if(check(i) == 1 && check( n - i) == 1)
printf("%d = %d + %d\n", n, i, n-i);
break;
}
cout << n;
return 0;
}
//哥德巴赫猜想拓展
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
bool check(int x)
{
int t = sqrt(x);
for(int i = 2; i <= t; i++)
{
if( x % i == 0) return 0;
}
return 1;
}
int main() {
int n;
cin >> n;
for(int j = 4; j<=n; j+=2)
{
bool flag = 0;
for(int i = 2; i<= j/2; i++)
{
if(check(i) == 1 && check( j - i) == 1 )
{
printf("%d=%d+%d\n", j, i, j-i);
break;
}
// if(flag == 0 || (flag == 1 && (i < (j-i)) ) )
// {
// printf("%d=%d+%d\n", j, i, j-i);
// flag = 1;
// }
}
}
return 0;
}