Untitled
unknown
plain_text
a year ago
742 B
6
Indexable
#User function Template for python3 import math class Solution: def isPrime (self, N): # As number 1 is not prime hence if N == 1: return 0 # Now we can check whether the N is divisible by any of the numbers, # The idea i am using is that, atleast one multiple should be below sqrt(n) # hence taking the upper limit to sqrt(n):- making the time complexity to sqrt(n) # Also the space complexity will be O(1) SqrtN = int((math.sqrt(N)) // 1) # print(SqrtN) for i in range(2,SqrtN + 1): if N % i == 0: return 0 return 1 # code here
Editor is loading...
Leave a Comment