File tree Expand file tree Collapse file tree 1 file changed +30
-21
lines changed Expand file tree Collapse file tree 1 file changed +30
-21
lines changed Original file line number Diff line number Diff line change 1
1
#include < bits/stdc++.h>
2
2
using namespace std ;
3
3
4
- bool isPrime (int n) {
5
- int cnt = 0 ;
6
- for (int i = 1 ; i <= sqrt (n); i++) {
7
- if (n == 1 ) return false ;
8
- if (n % i == 0 ) {
9
- cnt++;
10
- }
11
- if (cnt > 1 ) break ; // Break early if more than 1 divisor is found
12
- }
13
- if (cnt == 1 ) // A prime number should have exactly 2 divisors: 1 and itself
14
- return true ;
15
- else
16
- return false ;
4
+ bool isPrime (int n)
5
+ {
6
+ int cnt = 0 ;
7
+ for (int i = 1 ; i <= sqrt (n); i++)
8
+ {
9
+ if (n == 1 )
10
+ return false ;
11
+ if (n % i == 0 )
12
+ {
13
+ cnt++;
14
+ }
15
+ if (cnt > 1 )
16
+ break ; // Break early if more than 1 divisor is found
17
+ }
18
+ if (cnt == 1 ) // A prime number should have exactly 2 divisors: 1 and itself
19
+ return true ;
20
+ else
21
+ return false ;
17
22
}
18
23
19
- int main (){
20
- int n = 11 ;
21
- if (isPrime (n)){
22
- cout << " Prime" ;
23
- } else {
24
- cout << " Not Prime" ;
25
- }
26
- return 0 ;
24
+ int main ()
25
+ {
26
+ int n = 11 ;
27
+ if (isPrime (n))
28
+ {
29
+ cout << " Prime" ;
30
+ }
31
+ else
32
+ {
33
+ cout << " Not Prime" ;
34
+ }
35
+ return 0 ;
27
36
}
You can’t perform that action at this time.
0 commit comments