+ 1

Find prime number or not prime number

2nd Aug 2018, 3:52 PM
Ved Patel
Ved Patel - avatar
3 Respostas
+ 7
Maninder Singh Since multiplication is commutative, it is enough to check from 2 to sqrt(x) actually. It saves you a lot of "empty iterations" (and computation power) especially for really large numbers.
2nd Aug 2018, 8:22 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 5
x=int(input()) d=[] for i in range(1,x): if(x==1): print('Not Prime') elif(x%i==0): d.append(i) if(len(d)>1): print('Not Prime') break if(len(d)==1): print('Prime')
2nd Aug 2018, 4:24 PM
Maninder $ingh
Maninder $ingh - avatar
29th Oct 2019, 8:52 AM
Abhinav Koora