| Ruud H.G. van Tol on Mon, 05 Dec 2022 08:55:47 +0100 | 
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
| Re: A071521(n) | 
On 2022-11-27 11:21, Karim Belabas wrote:
A071521(n)= my(t=1);sum(k=1,logint(n,3),logint(n\t*=3,2)+1) when k = 1, we set t = 3 and compute logint(n \ 3, 2), where it was probably expected to compute logint(n \ 1, 2). If so,
The code indeed has a bug.
The original code, from Charles on the OEIS-page,
starts with t=1/3 and k=0:
a(n)=my(t=1/3); sum(k=0, logint(n, 3), t*=3; logint(n\t, 2)+1)
and I had messed that up. :(
And @Bill: thanks for mentioning the "Warning: compiler generates copy".
- - - - - -
Some timings:
{
a2_0(n)= my(t=1/3); sum(k=0, logint(n, 3), t*=3; logint(n\t, 2) +1)
}
{
a3_0(n)= my(t=1/2); sum(k=0, logint(n, 2), t+=t; logint(n\t, 3) +1)
}
{
a3_1(n)= sum(k=0, logint(n, 2), logint(n >> k, 3) +1)
}
? a2_0(2*10^30)
%9 = 3278
? a3_0(2*10^30)
%10 = 3278
? a3_1(2*10^30)
%11 = 3278
? a2_0(2^9999)
cpu time = 39 ms, real time = 39 ms.
%16 = 31548331
? a3_0(2^9999)
cpu time = 124 ms, real time = 124 ms.
%17 = 31548331
? a3_1(2^9999)
cpu time = 70 ms, real time = 71 ms.
%18 = 31548331
-- Ruud