forked from omonimus1/geeks-for-geeks-solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfullprime.cpp
More file actions
31 lines (29 loc) · 713 Bytes
/
Copy pathfullprime.cpp
File metadata and controls
31 lines (29 loc) · 713 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
// https://practice.geeksforgeeks.org/problems/full-prime2659/1/?problemStatus=unsolved&problemType=functional&difficulty[]=-2&page=2&sortBy=submissions&query=problemStatusunsolvedproblemTypefunctionaldifficulty[]-2page2sortBysubmissions
class Solution{
public:
bool IsPrime(int N)
{
if(N == 1)
return false;
for(int i= 2; i * i <= N; i++)
{
if(N%i == 0)
return false;
}
return true;
}
int fullPrime(int N){
if(!IsPrime(N))
return 0;
// check if all digits are prime
while(N>0)
{
if(!IsPrime(N%10))
{
return 0;
}
N /=10;
}
return 1;
}
};