|
Post by krzysztof on Aug 9, 2013 6:57:53 GMT -5
Very simple program for calculation of prime numbers: 'Program determines the prime numbers using the method of checking divisibility cls input "Enter limit"; n for p = 2 to n 'Instead of (p - 1) one can use sqr(p) for faster calculations for q = 2 to p - 1 'Instead of onecan use (p mod q = 0) if p / q = int(p / q) then goto [nextp] next q print p; " "; [nextp] next p end
|
|
|
Post by krzysztof on Aug 9, 2013 14:41:06 GMT -5
...And its small modification. Rejected numbers are saved as dots. 'Program determines the prime numbers using the method of checking divisibility 'The rejected numbers are recorded as dots cls
input "Enter limit"; n
for p = 2 to n 'Instead of (p - 1) one can use sqr(p) for faster calculations for q = 2 to p - 1 'Instead of one can use (p mod q = 0) if p / q = int(p / q) then goto [dot] next q
print p; goto [nextp]
[dot] print "."; [nextp] next p
end The numbers and dots are written in a single line, but it's worth look the version called Ulam spiral en.wikipedia.org/wiki/Ulam_spiral. The resulting gaps between the numbers are arranged in an interesting pattern.
|
|
|
Post by krzysztof on Aug 30, 2013 17:36:25 GMT -5
At the begining of the second page of " Run BASIC – A Breakthrough Web Application Server" document www.libertybasic.com/RunBASICBreakthrough.pdf there is an example of code for estimating time of prime numbers's calculation. It can display primes if we insert a command print prime inside if-then loop. But it is not a sieve of Eratostenes. Do You know what is the name ot that algorithm?
|
|