see any number cannot be divided by number which come after it. bole toh 56 wont be divided by 57,58,59,60..... and so on. means that in the loop try to check whether the number 56 is divisible from 1,2,3,4,......to 55 or not
if not print as prime.
2007-01-05 19:39:16
·
answer #1
·
answered by krishna 4
·
0⤊
0⤋
patnikrishna's answer is ok, but understand that ALL prime numbers other than 2 are odd. Also understand that non-prime numbers can be divisable by at least one of the lower prime numbers, and primes do not end in 5. So, you only have to look at odd numbers, and if you keep track of the primes, you can eliminate an odd number if it's evenly divisable by a smaller prime number.
For example, 2,3,5,7,11,13,17,19,23,29 are primes. We know 4,6,8,10,12, etc. are not primes because they are even (divisable by a lower prime (2)). We know that 9,15, 21 are not a prime because they're divisable by a lower prime (3).
So, while coding this algorithm will be a little more complicated than patnikrishna's suggestion, you'll certainly notice it generates numbers alot faster because it has to do less than half the work and fever divisions.
2007-01-05 19:58:44
·
answer #2
·
answered by BigRez 6
·
0⤊
0⤋