Discussion Room : IDC101

Python codes: Challenges, showcases, doubts and a lot more

Re: Python codes: Challenges, showcases, doubts and a lot more

by Kapil Paranjape -
Number of replies: 0

You don't need to calculate the square root. To know whether a number k is smaller than sqrt(n), you only need to calculate l=n//k and check whether l>k or not.

This can also be expensive if you need to do it for every k. However, in the given program, you can also use l*k=n to check whether k divides n.

Write a program using this method to check primality.