|
|
#5
风卷浪起2023-10-01 22:12
我做出来了!
(有点复杂)
#include <bits/stdc++.h>
using namespace std;
long long a[5], b[5];
bool prime(int n)
{
for (int i = 2; i <= sqrt(n); i ++)
{
if (n % i == 0)
{
return false;
}
}
return true;
}
int find_prime(int n, int f)
{
int i = n+f;
while (!prime(i))
{
i += f;
}
return i;
}
int main()
{
int n, num1, num2;
cin >> n;
if (prime(n))
{
a[1] = find_prime(n, -1);
a[0] = find_prime(a[1], -1);
a[2] = n;
a[3] = find_prime(a[2], 1);
a[4] = find_prime(a[3], 1);
cout << a[0] << endl;
cout << a[1] << endl;
cout << a[2] << endl;
cout << a[3] << endl;
cout << a[4] << endl;
}
else
{
a[1] = find_prime(n, -1);
a[0] = find_prime(a[1], -1);
a[2] = find_prime(a[1], 1);
a[3] = find_prime(a[2], 1);
a[4] = find_prime(a[3], 1);
num1 = abs(a[0] + a[1] + a[2] + a[3] + a[4] - 5 * n);
b[2] = find_prime(n, -1);
b[1] = find_prime(b[2], -1);
b[0] = find_prime(b[1], -1);
b[3] = find_prime(b[2], 1);
b[4] = find_prime(b[3], 1);
num2 = abs(b[0] + b[1] + b[2] + b[3] + b[4] - 5 * n);
if (num1 > num2)
{
cout << b[0] << endl;
cout << b[1] << endl;
cout << b[2] << endl;
cout << b[3] << endl;
cout << b[4] << endl;
}
else
{
cout << a[0] << endl;
cout << a[1] << endl;
cout << a[2] << endl;
cout << a[3] << endl;
cout << a[4] << endl;
}
}
}
|