-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path5.c
102 lines (65 loc) · 1.42 KB
/
5.c
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// Write a program to find if a given number N can be expressed as a sum of two prime numbers.
// Note: YOU MUST OPTIMIZE the logic to find whether a number is prime or not, as very large prime numbers are provided as input. If the logic is not optimized your program will NOT get executed within the given time limit.
// Input Format:
// First line contains total number of test cases, denoted by T.
// Next T lines will contain the value of N for each test case.
// Output Format:
// T lines containing either yes or no.
// Boundary Conditions / Constraints:
// 1 <= T <= 25
// 3 <= N <= 10^9
// Example Input/Output 1:
// Input:
// 5
// 20
// 12
// 23
// 34
// 16
// Output:
// yes
// yes
// no
// yes
// yes
// Explanation:
// 20 can be expressed as 17+3
// 12 can be expressed as 7+5
// 23 cannot be expressed as sum of two primes
// 34 can be expressed as 31+3 or 11+23 or 17+17
// 16 can be expressed as 11+5
#include<stdio.h>
#include<math.h>
int prime(int e)
{
for(int i=2;i<e;i++)
{
if(e%i==0)
return 0;
}
return 1;
}
int find(int n)
{
for(int i=2;i<n/2;i++)
{
if(prime(i))
{
if(prime(n-i))
{
return 1;
}
}
}
return 0;
}
int main()
{
int n,m;
scanf("%d",&m);
for(int i=0;i<m;i++)
{
scanf("%d",&n);
(find(n)==1)?printf("yes\n"):printf("no\n");
}
}