We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
def is_prime(n):
if n <= 1:
print('Not prime')
else:
prime = True
for i in range(2, int(math.sqrt(n))+1):
if n % i == 0:
prime = False
break
if prime:
print('Prime')
else:
print('Not prime')
T=int(input())
for i in range(T):
n = int(input())
is_prime(n)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Day 25: Running Time and Complexity
You are viewing a single comment's thread. Return to all comments →
python 3: import math
def is_prime(n): if n <= 1: print('Not prime') else: prime = True for i in range(2, int(math.sqrt(n))+1): if n % i == 0: prime = False break if prime: print('Prime') else: print('Not prime')
T=int(input())
for i in range(T): n = int(input()) is_prime(n)