-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSumOfPrime.cpp
More file actions
40 lines (39 loc) · 885 Bytes
/
SumOfPrime.cpp
File metadata and controls
40 lines (39 loc) · 885 Bytes
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
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{
//code
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while(t--)
{
int n;
cin >> n;
bool is_prime[n+1];
memset(is_prime, true, sizeof(is_prime));
is_prime[0] = is_prime[1] = false;
for(int i = 2 ; i <= n ; i++)
{
if(is_prime[i] && (long long)i*i <= n)
{
for(int j = i*i ; j <=n ; j += i)
is_prime[j] = false;
}
}
int flag = 0;
for(int i = 2 ; i <= n ; i++)
{
if(is_prime[i] && is_prime[n-i])
{
flag = 1;
cout << i << " " << n-i << "\n";
break;
}
}
if(!flag)
cout << -1 << "\n";
}
}