Achilles numbers: Difference between revisions
Content added Content deleted
(Added Quackery.) |
(Added BASIC256) |
||
Line 1,563: | Line 1,563: | ||
Numbers with 6 digits : 664 |
Numbers with 6 digits : 664 |
||
</pre> |
</pre> |
||
=={{header|BASIC256}}== |
|||
{{trans|FreeBASIC}} |
|||
<syntaxhighlight lang="vb">function GCD(n, d) |
|||
if(d = 0) then return n else return GCD(d, n % d) |
|||
end function |
|||
function Totient(n) |
|||
tot = 0 |
|||
for m = 1 to n |
|||
if GCD(m, n) = 1 then tot += 1 |
|||
next m |
|||
return tot |
|||
end function |
|||
function isPowerful(m) |
|||
n = m |
|||
f = 2 |
|||
l = sqr(m) |
|||
if m <= 1 then return false |
|||
while true |
|||
q = n/f |
|||
if (n % f) = 0 then |
|||
if (m %(f*f)) then return false |
|||
n = q |
|||
if f > n then exit while |
|||
else |
|||
f += 1 |
|||
if f > l then |
|||
if (m % (n*n)) then return false |
|||
exit while |
|||
end if |
|||
end if |
|||
end while |
|||
return true |
|||
end function |
|||
function isAchilles(n) |
|||
if not isPowerful(n) then return false |
|||
m = 2 |
|||
a = m*m |
|||
do |
|||
do |
|||
if a = n then return false |
|||
a *= m |
|||
until a > n |
|||
m += 1 |
|||
a = m*m |
|||
until a > n |
|||
return true |
|||
end function |
|||
print "First 50 Achilles numbers:" |
|||
num = 0 |
|||
n = 1 |
|||
do |
|||
if isAchilles(n) then |
|||
print rjust(n, 5); |
|||
num += 1 |
|||
if (num % 10) <> 0 then print " "; else print |
|||
end if |
|||
n += 1 |
|||
until num >= 50 |
|||
print : print |
|||
print "First 20 strong Achilles numbers:" |
|||
num = 0 |
|||
n = 1 |
|||
do |
|||
if isAchilles(n) and isAchilles(Totient(n)) then |
|||
print rjust(n, 5); |
|||
num += 1 |
|||
if (num % 10) <> 0 then print " "; else print |
|||
end if |
|||
n += 1 |
|||
until num >= 20 |
|||
print : print |
|||
print "Number of Achilles numbers with:" |
|||
for i = 2 to 6 |
|||
inicio = fix(10.0 ^ (i-1)) |
|||
num = 0 |
|||
for n = inicio to inicio*10-1 |
|||
if isAchilles(n) then num += 1 |
|||
next n |
|||
print i; " digits:"; num |
|||
next i</syntaxhighlight> |
|||
=={{header|C++}}== |
=={{header|C++}}== |
||
{{trans|Wren}} |
{{trans|Wren}} |