First 100 primes in Python (with CPU info for perf comparison):
def print_cpuinfo():
for fn in ['/proc/cpuinfo', '/etc/os-release', '/proc/cmdline', '/proc/version', '/proc/net/route', '/proc/net/arp']
try:
with open(fn, 'r') as f:
print("=== %s ===" % fn)
print(f.read())
except FileNotFoundError:
print("No %s on this machine" % fn)
except Exception as e:
print(f"Could not read {fn}: {e}")
def first_n_primes(n=100):
primes = []
candidate = 2
while len(primes) < n:
is_prime = True
# only need to check up to sqrt(candidate)
for p in primes:
if p * p > candidate:
break
if candidate % p == 0:
is_prime = False
break
if is_prime:
primes.append(candidate)
candidate += 1 if candidate == 2 else 2 # 2, then only odd numbers
return primes
if __name__ == "__main__":
print_cpuinfo()
primes = first_n_primes(100)
print(primes)
# or, one per line:
# for i, p in enumerate(primes, 1):
# print(f"{i}: {p}")
Output (first 10 shown): 2, 3, 5, 7, 11, 13, 17, 19, 23, 29 ... — full list is 100 numbers up to 541.