Python Day 25 : Running Time and Complexity | HackerRank 30 Days of Code Solutions

 

Code:

# Enter your code here. Read input from STDIN. Print output to STDOUT
from itertools import count, islice

n = int(input())
for i in range(n):
    x, prime = int(input()), True
    sq = int(x**0.5)-1
    if x<2: prime = False
    else:
        for num in islice(count(2), sq):
            if not x%num:
                prime = False
    print("Prime") if prime else print("Not prime")

AJ Blogs

Hello everyone, My name Arth and I like to write about what I learn. Follow My Website - https://sites.google.com/view/aj-blogs/home

Post a Comment

Previous Post Next Post
Best Programming Books

Facebook

AJ Facebook
Checkout Our Facebook Page
AJ Blogs
Checkout Our Instagram Page