-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuestion 36.py
More file actions
24 lines (18 loc) · 754 Bytes
/
Question 36.py
File metadata and controls
24 lines (18 loc) · 754 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
# Concept name : Number Problem
# Question : Prime Number
# Given a number n, determine whether it is a prime number or not.
# Note: A prime number is a number greater than 1 that has no positive divisors other than 1 and itself.
# Examples :
# Input: n = 7
# Output: true
# Explanation: 7 has exactly two divisors: 1 and 7, making it a prime number.
# Solution :
class Solution:
def isPrime(self, n):
if n<2:
return False
sqr=math.sqrt(n)
for i in range(2,int(sqr)+1):
if n%i==0:
return False
return True