-
Notifications
You must be signed in to change notification settings - Fork 16
/
chef and prime
126 lines (117 loc) · 2.95 KB
/
chef and prime
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include <iostream>
using namespace std;
#include<stdio.h>
int N[200],count,ans;
void printCombination1(int [], int, int,int);
void printCombination2(int [], int, int,int);
void combinationUtil1(int [], int [], int, int, int, int,int);
void combinationUtil2(int [], int [], int, int, int, int,int);
int main()
{
int a[100],T,k;
cin>>T;
for(int i=0;i<T;i++)
{
cin>>N[i];
}
for(int g=0;g<T;g++){
ans=0;k=0;
for(int i=2;i<=N[g];i++)
{
count=0;
for(int j=1;j<=N[g];j++)
{
if(i%j==0)
count++;
if(count==3)
break;
}
if(count==2)
{
a[k]=i;
k++;
}
}
printCombination1(a,k,4,g);
printCombination2(a,k,2,g);
if(ans==1)
cout<<"YES"<<"\n";
else
cout<<"NO"<<"\n";
}
return 0;
}
void printCombination1(int arr[], int n, int r,int g)
{
// A temporary array to store all combination one by one
int data[r];
// all combination using temprary array 'data[]'
combinationUtil1(arr, data, 0, n-1, 0, r,g);
}
void printCombination2(int arr[], int n, int r,int g)
{
// A temporary array to store all combination one by one
int data[r];
// all combination using temprary array 'data[]'
combinationUtil2(arr, data, 0, n-1, 0, r,g);
}
void combinationUtil1(int arr[], int data[], int start, int end,
int index, int r,int g)
{
if (index == r)
{
if(N[g] == (data[0]*data[1]) + (data[1]*data[0]) )
ans=1;
if(N[g] == (data[0]*data[1]) + (data[1]*data[2]) )
ans=1;
if(N[g] == (data[0]*data[1]) + (data[1]*data[3]) )
ans=1;
if(N[g] == (data[0]*data[2]) + (data[1]*data[0]) )
ans=1;
if(N[g] == (data[0]*data[2]) + (data[1]*data[2]) )
ans=1;
if(N[g] == (data[0]*data[2]) + (data[1]*data[3]) )
ans=1;
if(N[g] == (data[0]*data[3]) + (data[2]*data[1]) )
ans=1;
if(N[g] == (data[0]*data[3]) + (data[1]*data[0]) )
ans=1;
if(N[g] == (data[0]*data[3]) + (data[1]*data[2]) )
ans=1;
if(N[g] == (data[0]*data[3]) + (data[1]*data[3]) )
ans=1;
if(N[g] == (data[2]*data[3]) + (data[0]*data[1]) )
ans=1;
if(N[g] == (data[2]*data[3]) + (data[0]*data[2]) )
ans=1;
if(N[g] == (data[2]*data[3]) + (data[0]*data[3]) )
ans=1;
if(N[g] == (data[2]*data[3]) + (data[1]*data[2]) )
ans=1;
if(N[g] == (data[2]*data[3]) + (data[1]*data[3]) )
ans=1;
return;
}
if(ans==1)
return;
for (int i=start; i<=end && end-i+1 >= r-index; i++)
{
data[index] = arr[i];
combinationUtil1(arr, data, i+1, end, index+1, r,g);
}
}
void combinationUtil2(int arr[], int data[], int start, int end,
int index, int r,int g)
{
if (index == r)
{
if(N[g] == (data[0]*data[1]) + (data[0]*data[1]))
ans=1;
return;
}
for (int i=start; i<=end && end-i+1 >= r-index; i++)
{
data[index] = arr[i];
combinationUtil2(arr, data, i+1, end, index+1, r,g);
}
}