0
How to Detect prime numbers?
between 2-1000
10 odpowiedzi
+ 2
To detect if a number n is prime, check if any number from 2 to square root of n divides n.
To find all primes in a range (2 - 1000), you can use sieve of erathosthenes, described here
https://www.sololearn.com/learn/969/?ref=app
+ 2
oh, didn't see that one, sloppy
+ 1
this code contains a function that detects primes.
you can use it on every number in the range.
https://code.sololearn.com/c7I7yNzPppBS/?ref=app
+ 1
Debjit Mutsuddi
You can find some codes in the comments of the task linked by michal
+ 1
davy hermans Your code gives wrong answer for 2.
It is not actuallynecessary to iterate to n/2, square root of n suffices
+ 1
Debjit Mutsuddi , thanks. Fixed it.
0
can't find the code
0
but thanx anyway
0
thanx
0
davy hermans Still doesn't work. Put return true outside of the loop