-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsumofprime.cpp
54 lines (53 loc) · 1.06 KB
/
sumofprime.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
bool prime(int n)
{
if (n <= 1)
return false;
for (int i = 2; i <= n/2; i++)
if (n % i == 0)
return false;
return true;
}
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
vector <int> v;
for(int i=2;i<n;i++)
{
if(prime(i))
{
v.push_back(i);
}
}
int l=0,r=v.size()-1;
int f=0;
while(l<=r)
{
int s=v[l]+v[r];
if(s<n)
l++;
else if(s>n)
r--;
else
{
f=1;
if(l==r)
{
cout<<v[l]<<" "<<v[l];
}
else
cout<<v[l]<<" "<<v[r];break;
}
}
if(!f)cout<<"-1";
cout<<endl;
}
return 0;
}