Difference between revisions of "Primes"
Jump to navigation
Jump to search
| Line 12: | Line 12: | ||
def main(): | def main(): | ||
count = 3 | count = 3 | ||
| − | |||
while True: | while True: | ||
isprime = True | isprime = True | ||
| − | |||
for x in range(2, int(math.sqrt(count) + 1)): | for x in range(2, int(math.sqrt(count) + 1)): | ||
if count % x == 0: | if count % x == 0: | ||
isprime = False | isprime = False | ||
break | break | ||
| − | |||
if isprime: | if isprime: | ||
print count | print count | ||
| − | |||
count += 1 | count += 1 | ||
<syntaxhighlight> | <syntaxhighlight> | ||
Revision as of 04:32, 3 June 2021
Factor numbers in a given range in a shell:
for value in {2000..2021}
do echo `factor $value`
done
Python simple prime finding program: <syntaxhighlight lang=python> import math
def main():
count = 3
while True:
isprime = True
for x in range(2, int(math.sqrt(count) + 1)):
if count % x == 0:
isprime = False
break
if isprime:
print count
count += 1
<syntaxhighlight>