RosettaCodeData/Task/Long-primes/11l/long-primes.11l
2023-07-01 13:44:08 -04:00

53 lines
1.1 KiB
Text
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

F sieve(limit)
[Int] primes
V c = [0B] * (limit + 1)
V p = 3
L
V p2 = p * p
I p2 > limit
L.break
L(i) (p2 .< limit).step(2 * p)
c[i] = 1B
L
p += 2
I !c[p]
L.break
L(i) (3 .< limit).step(2)
I !(c[i])
primes.append(i)
R primes
F findPeriod(n)
V r = 1
L(i) 1 .< n
r = (10 * r) % n
V rr = r
V period = 0
L
r = (10 * r) % n
period++
I r == rr
L.break
R period
V primes = sieve(64000)
[Int] longPrimes
L(prime) primes
I findPeriod(prime) == prime - 1
longPrimes.append(prime)
V numbers = [500, 1000, 2000, 4000, 8000, 16000, 32000, 64000]
V count = 0
V index = 0
V totals = [0] * numbers.len
L(longPrime) longPrimes
I longPrime > numbers[index]
totals[index] = count
index++
count++
totals.last = count
print(The long primes up to 500 are:)
print(String(longPrimes[0 .< totals[0]]).replace(,, ))
print("\nThe number of long primes up to:")
L(total) totals
print( #5 is #..format(numbers[L.index], total))