-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem41.cpp
More file actions
51 lines (47 loc) · 886 Bytes
/
Problem41.cpp
File metadata and controls
51 lines (47 loc) · 886 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
41
42
43
44
45
46
47
48
49
50
51
//7652413
#include<bits/stdc++.h>
#define ll long long
using namespace std;
bool isprime(ll num)
{
if(num==1)
return false;
for(ll i = 2;i<=sqrt(num);i++)
{
if(num%i==0)
return false;
}
return true;
}
void check(int arr[],int n)
{
do
{
ll val = 0;
for(int i=0;i<n;i++)
val = val*10 + arr[i];
if(isprime(val))
{
cout<<val<<"\n";
}
}while(next_permutation(arr,arr+n));
}
int main()
{
ll ans = 0;
int arr[] = {1,2,3,4,5,6,7,8,9};
for(int i=1;i<=9;i++)
{
check(arr,i);
arr[0] = 1;
arr[1] = 2;
arr[2] = 3;
arr[3] = 4;
arr[4] = 5;
arr[5] = 6;
arr[6] = 7;
arr[7] = 8;
arr[8] = 9;
}
cout<<ans<<"\n";
}