Data update
This commit is contained in:
parent
4d5544505c
commit
4924dd0264
3073 changed files with 55820 additions and 4408 deletions
33
Task/Totient-function/Pluto/totient-function.pluto
Normal file
33
Task/Totient-function/Pluto/totient-function.pluto
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
local function totient(n)
|
||||
local tot = n
|
||||
local i = 2
|
||||
while i * i <= n do
|
||||
if n % i == 0 then
|
||||
while n % i == 0 do n //= i end
|
||||
tot -= tot // i
|
||||
end
|
||||
if i == 2 then i = 1 end
|
||||
i += 2
|
||||
end
|
||||
if n > 1 do tot -= tot // n end
|
||||
return tot
|
||||
end
|
||||
|
||||
print(" n phi prime")
|
||||
print("---------------")
|
||||
local count = 0
|
||||
for n = 1, 25 do
|
||||
local tot = totient(n)
|
||||
local isPrime = (n - 1) == tot
|
||||
if isPrime then ++count end
|
||||
print(string.format("%2d %2d %s", n, tot, isPrime))
|
||||
end
|
||||
print("\nNumber of primes up to 25 = " .. count)
|
||||
for n = 26, 100_000 do
|
||||
local tot = totient(n)
|
||||
if tot == n - 1 then ++count end
|
||||
if n == 100 or n == 1_000 or n % 10_000 == 0 then
|
||||
local ns = string.format("%-6d", n)
|
||||
print($"\nNumber of primes up to {ns} = {count}")
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue