-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday25.py
More file actions
31 lines (26 loc) · 891 Bytes
/
day25.py
File metadata and controls
31 lines (26 loc) · 891 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
"""
A prime is a natural number greater than 1 that has no positive divisors other than 1 and itself.
Given a number, n , determine and print whether it's Prime or Not prime.
Note: If possible, try to come up with a O(n**0.5) primality algorithm,
or see what sort of optimizations you come up with for an O(n) algorithm.
Be sure to check out the Editorial after submitting your code!
"""
def test_prime(number):
prime = True
sqrt = round(number ** 0.5)
if number == 1:
print('Not prime')
else:
for i in range(2,sqrt+1):
if number % i == 0:
prime = False
break
if prime == True:
print('Prime')
else:
print('Not prime')
if __name__ == '__main__':
size = int(input())
for _ in range(size):
number = int(input())
test_prime(number)