Write a program to check whether the given number is prime or not...! By a simple technique | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Write a program to check whether the given number is prime or not...! By a simple technique

If we want to check the given number is prime (ex 97) then no need to check all 97 numbers... Just by checking upto 10 is enough because nearest number of squareroot of 97 is 10...so if any number upto 10 does not divide 97 then the given number is prime

6th Oct 2017, 3:54 PM
Gnani Prasad Reddy
Gnani Prasad Reddy - avatar
6 Answers
+ 13
If I understood well, you want a program that not try to divide a number until itself less one before concluding that the number is prime. According to your example 97, it is enough to try to divide it until 9 to conclude that 97 is a prime number (division from 10 to 96 is not needed). I can add that also try to divide for a non prime number is useless, so in case of 97 is enough try to divide for 2, 3, 5 and 7 to say that 97 is a prime number. I have a code that to this, it is not so simple since it will provide more info, but maybe can be useful. https://code.sololearn.com/cnBDO3pmRV7U/#java What you request is in createPrimeList. I hope you like it.
9th Oct 2017, 6:37 AM
Daniele Gaito
Daniele Gaito - avatar
+ 2
Bro once check the logic..... It is giving wrong output...
10th Oct 2017, 11:42 AM
Gnani Prasad Reddy
Gnani Prasad Reddy - avatar
+ 1
example not helping
8th Oct 2017, 4:22 AM
Abu Shahid
Abu Shahid - avatar
+ 1
I have edited the question to understand you more clearly.... Plzz post if you have any doubts....! Happy to help
9th Oct 2017, 3:23 AM
Gnani Prasad Reddy
Gnani Prasad Reddy - avatar
10th Oct 2017, 7:26 AM
Abu Shahid
Abu Shahid - avatar
0
https://code.sololearn.com/cAr2wKtGL796/?ref=app
3rd Dec 2017, 6:52 PM
Cuttek
Cuttek - avatar