|
|
A053610
|
|
Number of positive squares needed to sum to n using the greedy algorithm.
|
|
28
|
|
|
1, 2, 3, 1, 2, 3, 4, 2, 1, 2, 3, 4, 2, 3, 4, 1, 2, 3, 4, 2, 3, 4, 5, 3, 1, 2, 3, 4, 2, 3, 4, 5, 3, 2, 3, 1, 2, 3, 4, 2, 3, 4, 5, 3, 2, 3, 4, 5, 1, 2, 3, 4, 2, 3, 4, 5, 3, 2, 3, 4, 5, 3, 4, 1, 2, 3, 4, 2, 3, 4, 5, 3, 2, 3, 4, 5, 3, 4, 5, 2, 1, 2, 3, 4, 2, 3, 4, 5, 3, 2, 3, 4, 5, 3, 4, 5, 2, 3, 4, 1, 2, 3, 4
(list;
graph;
refs;
listen;
history;
text;
internal format)
|
|
|
OFFSET
|
1,2
|
|
COMMENTS
|
Define f(n) = n - x^2 where (x+1)^2 > n >= x^2. a(n) = number of iterations in f(...f(f(n))...) to reach 0.
a(n) = 1 iff n is a perfect square.
The sequence could have started with a(0)=0. - Thomas Ordowski, Jul 12 2014
|
|
LINKS
|
|
|
FORMULA
|
|
|
EXAMPLE
|
7=4+1+1+1, so 7 requires 4 squares using the greedy algorithm, so a(7)=4.
|
|
MAPLE
|
local a, x;
a := 0 ;
x := n ;
while x > 0 do
a := a+1 ;
end do:
a ;
|
|
MATHEMATICA
|
f[n_] := (n - Floor[Sqrt[n]]^2); g[n_] := (m = n; c = 1; While[a = f[m]; a != 0, c++; m = a]; c); Table[ g[n], {n, 1, 105}]
|
|
PROG
|
(Haskell)
a053610 n = s n $ reverse $ takeWhile (<= n) $ tail a000290_list where
s _ [] = 0
s m (x:xs) | x > m = s m xs
| otherwise = m' + s r xs where (m', r) = divMod m x
(Python)
from math import isqrt
c = 0
while n:
n -= isqrt(n)**2
c += 1
|
|
CROSSREFS
|
|
|
KEYWORD
|
nonn
|
|
AUTHOR
|
|
|
STATUS
|
approved
|
|
|
|