Computer Science Canada math problems |
Author: | TokenHerbz [ Mon Oct 10, 2005 12:48 am ] | ||
Post subject: | math problems | ||
I want to make a code that asks the user for 2 numbers, and inbetween these numbers it will print out numbers which are only able to divide by its self, and 1 evenly... Ex, 1,2,3,5,7,11 ( i think )
Help me please |
Author: | zylum [ Mon Oct 10, 2005 1:14 am ] | ||
Post subject: | |||
so you want to print the primes in a range of numbers?
|
Author: | Drakain Zeil [ Mon Oct 10, 2005 9:58 am ] |
Post subject: | |
I ran through a for loop with i as a count. if i was not divisable by the number,(use mod), then I would output. You only need to run the loop from: a..(b/2)+1 And a decent range for prime check is (a/3)-1..(b/2)+1 |
Author: | GlobeTrotter [ Mon Oct 10, 2005 7:25 pm ] |
Post subject: | |
Drakain Zeil wrote: I ran through a for loop with i as a count.
if i was not divisable by the number,(use mod), then I would output. You only need to run the loop from: a..(b/2)+1 And a decent range for prime check is (a/3)-1..(b/2)+1 Actually to check for a given prime, you only need to check if the number is divisible by any prime between 0 and the root of the number. |
Author: | jamonathin [ Mon Oct 10, 2005 7:38 pm ] |
Post subject: | |
Drakain Zeil wrote: Actually to check for a given prime, you only need to check if the number is divisible by any prime between 0 and the root of the number. But if we're looking for a prime number, how would be divide it by primes to find out if it's prime? |
Author: | Cervantes [ Mon Oct 10, 2005 8:04 pm ] |
Post subject: | |
jamonathin wrote: But if we're looking for a prime number, how would be divide it by primes to find out if it's prime? Start from the bottom up. ![]() |