September Morn Update
This commit is contained in:
parent
4e2d22a71d
commit
aac6731f2c
6856 changed files with 141342 additions and 21127 deletions
28
Task/Arithmetic-Rational/Phix/arithmetic-rational-2.phix
Normal file
28
Task/Arithmetic-Rational/Phix/arithmetic-rational-2.phix
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
include builtins/mpfr.e
|
||||
function is_perfect(integer num)
|
||||
mpq tot = mpq_init(),
|
||||
fth = mpq_init()
|
||||
sequence f = factors(num,1)
|
||||
for i=1 to length(f) do
|
||||
mpq_set_si(fth,1,f[i])
|
||||
mpq_add(tot,tot,fth)
|
||||
end for
|
||||
return mpq_cmp_si(tot,2,1)=0
|
||||
end function
|
||||
|
||||
procedure get_perfect_numbers()
|
||||
atom t0 = time()
|
||||
for i=2 to power(2,19) do
|
||||
if is_perfect(i) then
|
||||
printf(1,"perfect: %d\n",i)
|
||||
end if
|
||||
end for
|
||||
printf(1,"elapsed: %3.2f seconds\n",time()-t0)
|
||||
|
||||
integer pn5 = power(2,12)*(power(2,13)-1) -- 5th perfect number
|
||||
if is_perfect(pn5) then
|
||||
printf(1,"perfect: %d\n",pn5)
|
||||
end if
|
||||
end procedure
|
||||
|
||||
get_perfect_numbers()
|
||||
Loading…
Add table
Add a link
Reference in a new issue