PAIRPR1 Pair of primes
Problem : PAIRPR1
Given an integer nn (between 11 and 104104) find two prime numbers (possibly same) p1,p2p1,p2 such that p1+p2=np1+p2=n
In case there are multiple solutions, you can output any of them.
If there is no solution, then print -1 -1
instead.
#include <iostream>
using namespace std;
bool check_prime(int n);
int main()
{
int t;
cin>>t;
while(t--)
{
int n,i;
bool flag=false;
cin >> n;
for(i = 2; i <= n/2; ++i)
{
if (check_prime(i))
{
if (check_prime(n - i))
{
cout<<i<<" "<<n-i<<endl;
flag = true;
break;
}
}
}
if (!flag)
cout<<-1 <<" "<<-1<<endl;
}
return 0;
}
bool check_prime(int n)
{
int i;
bool is_prime=true;
if(n==0||n==1)
{
is_prime = false;
}
for(i = 2; i <= n/2; ++i)
{
if(n%i==0)
{
is_prime = false;
break;
}
}
return is_prime;
}