Data update
This commit is contained in:
parent
5af6d93694
commit
796d366b97
455 changed files with 7413 additions and 1900 deletions
|
|
@ -24,7 +24,10 @@ BEGIN
|
|||
print( ( " n phi(n) remarks", newline ) );
|
||||
FOR n TO 25 DO
|
||||
INT tn = totient( n );
|
||||
print( ( whole( n, -2 ), ": ", whole( tn, -5 ), IF tn = n - 1 AND tn /= 0 THEN " n is prime" ELSE "" FI, newline ) )
|
||||
print( ( whole( n, -2 ), ": ", whole( tn, -5 )
|
||||
, IF tn = n - 1 AND tn /= 0 THEN " n is prime" ELSE "" FI, newline
|
||||
)
|
||||
)
|
||||
OD;
|
||||
# use the totient function to count primes #
|
||||
INT n100 := 0, n1000 := 0, n10000 := 0, n100000 := 0;
|
||||
|
|
|
|||
40
Task/Totient-function/EasyLang/totient-function.easy
Normal file
40
Task/Totient-function/EasyLang/totient-function.easy
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
func totient n .
|
||||
tot = n
|
||||
i = 2
|
||||
while i <= sqrt n
|
||||
if n mod i = 0
|
||||
while n mod i = 0
|
||||
n = n div i
|
||||
.
|
||||
tot -= tot div i
|
||||
.
|
||||
if i = 2
|
||||
i = 1
|
||||
.
|
||||
i += 2
|
||||
.
|
||||
if n > 1
|
||||
tot -= tot div n
|
||||
.
|
||||
return tot
|
||||
.
|
||||
numfmt 0 3
|
||||
print " N Prim Phi"
|
||||
for n = 1 to 25
|
||||
tot = totient n
|
||||
x$ = " "
|
||||
if n - 1 = tot
|
||||
x$ = " x "
|
||||
.
|
||||
print n & x$ & tot
|
||||
.
|
||||
print ""
|
||||
for n = 1 to 100000
|
||||
tot = totient n
|
||||
if n - 1 = tot
|
||||
cnt += 1
|
||||
.
|
||||
if n = 100 or n = 1000 or n = 10000 or n = 100000
|
||||
print n & " - " & cnt & " primes"
|
||||
.
|
||||
.
|
||||
44
Task/Totient-function/Lua/totient-function-2.lua
Normal file
44
Task/Totient-function/Lua/totient-function-2.lua
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
do
|
||||
function totient( n ) -- returns the number of integers k where 1 <= k <= n that are mutually prime to n
|
||||
if n < 3 then return 1
|
||||
elseif n == 3 then return 2
|
||||
else
|
||||
local result, v, i = n, n, 2
|
||||
while i * i <= v do
|
||||
if v % i == 0 then
|
||||
while v % i == 0 do v = math.floor( v / i ) end
|
||||
result = result - math.floor( result / i )
|
||||
end
|
||||
if i == 2 then
|
||||
i = 1
|
||||
end
|
||||
i = i + 2
|
||||
end
|
||||
if v > 1 then result = result - math.floor( result / v ) end
|
||||
return result
|
||||
end
|
||||
end
|
||||
-- show the totient function values for the first 25 integers
|
||||
io.write( " n phi(n) remarks\n" )
|
||||
for n = 1,25 do
|
||||
local tn = totient( n )
|
||||
io.write( string.format( "%2d", n ), ": ", string.format( "%5d", tn )
|
||||
, ( tn == n - 1 and tn ~= 0 and " n is prime" or "" )
|
||||
, "\n"
|
||||
)
|
||||
end
|
||||
-- use the totient function to count primes
|
||||
local n100, n1000, n10000, n100000 = 0, 0, 0, 0
|
||||
for n = 1,100000 do
|
||||
if totient( n ) == n - 1 then
|
||||
if n <= 100 then n100 = n100 + 1 end
|
||||
if n <= 1000 then n1000 = n1000 + 1 end
|
||||
if n <= 10000 then n10000 = n10000 + 1 end
|
||||
if n <= 100000 then n100000 = n100000 + 1 end
|
||||
end
|
||||
end
|
||||
io.write( "There are ", string.format( "%6d", n100 ), " primes below 100\n" )
|
||||
io.write( "There are ", string.format( "%6d", n1000 ), " primes below 1 000\n" )
|
||||
io.write( "There are ", string.format( "%6d", n10000 ), " primes below 10 000\n" )
|
||||
io.write( "There are ", string.format( "%6d", n100000 ), " primes below 100 000\n" )
|
||||
end
|
||||
|
|
@ -1,8 +1,3 @@
|
|||
[ [ dup while
|
||||
tuck mod again ]
|
||||
drop abs ] is gcd ( n n --> n )
|
||||
|
||||
|
||||
[ 0 swap dup times
|
||||
[ i over gcd
|
||||
1 = rot + swap ]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue