Greatest prime dividing the n-th cubefree number: Difference between revisions

m
→‎{{header|Phix}}: extended to 1e11, matching the Pascal output
m (→‎Version 2: Added a libheader.)
m (→‎{{header|Phix}}: extended to 1e11, matching the Pascal output)
Line 583:
</pre>
=={{header|Phix}}==
Quite possibly flawed, but it does finishat least complete to 1e9 in the blink of an eye, and 93s for 1e11.
<syntaxhighlight lang="phix">
with javascript_semantics
Line 595:
-- but only if cubes_before(n-1)==cubes_before(n),
-- otherwise cubes_before(cubicate) isn't really very meaningful.
integeratom r = 0
bool xpm = true -- extend prior multiples
sequence pm = {}
for i=1 to n do -- (or eg floor(cbrtpower(n,1/3))) do
atom p3 = power(get_prime(i),3)
if p3>n then exit end if
integer k = floor(n/p3)
for mask=1 to power(2,length(pm))-1 do
integer m = mask, mi = 0, bc = count_bits(mask)
atom kpm = p3
while m do
Line 613:
end while
if kpm>n then
if count_bits(mask)bc=1 then
xpm = false
pm = pm[1..mi-1]
Line 622:
integer l = floor(n/kpm)
-- DEV insufficient kludge... (probably)
--if count_bits(mask)bc=1 then
if odd(count_bits(mask)bc) then -- match Wren
k -= l
else
Line 646:
end while
-- bisect until we have a possible...
atom t1 = time()+1
while true do
mid = floor((lo+hi)/2)
Line 661 ⟶ 662:
else
hi = mid
end if
if time()>t1 then
progress("bisecting %,d..%,d...\r",{lo,hi})
t1 = time()+1
end if
end while
Line 667 ⟶ 672:
 
function A370833(atom n)
if n=1 then return {1,1,1} end if
atom nth = cube_free(n)
sequence f = prime_powers(nth)
return {n,nth,f[$][1]}
end function
 
atom t0 = time()
printf(1,"Firstsequence 100f100 terms= of a[n]:\n%s\n",join_byvslice(apply(tagset(100),A370833),1,10," ",fmt:="%3d")3)
printf(1,"First 100 terms of a[n]:\n%s\n",join_by(f100,1,10," ",fmt:="%3d"))
for n in sq_power(10,tagset(711,3)) do
printf(1,"The %,dth term of a[n] is %,d with highest divisor %,d.\n",{n,A370833(n)})
end for
?elapsed(time()-t0)
Line 694 ⟶ 700:
107 109 11 37 113 19 23 29 13 59
 
The 1,000th term of a[n] is 1,199 with highest divisor 109.
The 10,000th term of a[n] is 12,019 with highest divisor 101.
The 100,000th term of a[n] is 120,203 with highest divisor 1,693.
The 1,000,000th term of a[n] is 1,202,057 with highest divisor 1,202,057.
The 10,000,000th term of a[n] is 12,020,570 with highest divisor 1,202,057.
The 100,000,000th term of a[n] is 120,205,685 with highest divisor 20,743.
"0.1s"
The 1,000,000,000th term of a[n] is 1,202,056,919 with highest divisor 215,461.
The 10,000,000,000th term of a[n] is 12,020,569,022 with highest divisor 1,322,977.
The 100,000,000,000th term of a[n] is 120,205,690,298 with highest divisor 145,823.
"1 minute and 33s"
</pre>
 
7,820

edits