Data update
This commit is contained in:
parent
5af6d93694
commit
796d366b97
455 changed files with 7413 additions and 1900 deletions
|
|
@ -1,36 +0,0 @@
|
|||
-- Return the greatest common denominator of x and y
|
||||
function gcd (x, y)
|
||||
return y == 0 and math.abs(x) or gcd(y, x % y)
|
||||
end
|
||||
|
||||
-- Return the totient number for n
|
||||
function totient (n)
|
||||
local count = 0
|
||||
for k = 1, n do
|
||||
if gcd(n, k) == 1 then count = count + 1 end
|
||||
end
|
||||
return count
|
||||
end
|
||||
|
||||
-- Determine (inefficiently) whether p is prime
|
||||
function isPrime (p)
|
||||
return totient(p) == p - 1
|
||||
end
|
||||
|
||||
-- Output totient and primality for the first 25 integers
|
||||
print("n", string.char(237), "prime")
|
||||
print(string.rep("-", 21))
|
||||
for i = 1, 25 do
|
||||
print(i, totient(i), isPrime(i))
|
||||
end
|
||||
|
||||
-- Count the primes up to 100, 1000 and 10000
|
||||
local pCount, i, limit = 0, 1
|
||||
for power = 2, 4 do
|
||||
limit = 10 ^ power
|
||||
repeat
|
||||
i = i + 1
|
||||
if isPrime(i) then pCount = pCount + 1 end
|
||||
until i == limit
|
||||
print("\nThere are " .. pCount .. " primes below " .. limit)
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue