Write a program to check if a number is prime in minimum iterations(time).. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Write a program to check if a number is prime in minimum iterations(time)..

hello,i have written a program n I want u to check if it can become more time efficient but reducing the no. of iterations....I have reduced the iterations as to half https://code.sololearn.com/cPa108ugyFbN/?ref=app https://code.sololearn.com/cPa108ugyFbN/?ref=app

8th Oct 2017, 4:42 AM
Abu Shahid
Abu Shahid - avatar
2 Answers
+ 2
https://code.sololearn.com/cPa108ugyFbN/?ref=app
8th Oct 2017, 6:02 AM
Abu Shahid
Abu Shahid - avatar
+ 7
For even smaller iterations, you may reduce the loop to maximum of Math.sqrt(no); This will also work in the same way, and will be faster.
8th Oct 2017, 5:10 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar