cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

Showing 1-7 of 7 results.

A286368 a(n) = 4*A072401(n) + 2*A229062(n) + A010052(n).

Original entry on oeis.org

3, 2, 0, 3, 2, 0, 4, 2, 3, 2, 0, 0, 2, 0, 4, 3, 2, 2, 0, 2, 0, 0, 4, 0, 3, 2, 0, 4, 2, 0, 4, 2, 0, 2, 0, 3, 2, 0, 4, 2, 2, 0, 0, 0, 2, 0, 4, 0, 3, 2, 0, 2, 2, 0, 4, 0, 0, 2, 0, 4, 2, 0, 4, 3, 2, 0, 0, 2, 0, 0, 4, 2, 2, 2, 0, 0, 0, 0, 4, 2, 3, 2, 0, 0, 2, 0, 4, 0, 2, 2, 0, 4, 0, 0, 4, 0, 2, 2, 0, 3, 2, 0, 4, 2, 0, 2, 0, 0, 2, 0, 4, 4, 2, 0, 0, 2, 2, 0, 4, 0
Offset: 1

Views

Author

Antti Karttunen, May 08 2017

Keywords

Comments

Partitions natural numbers to the same equivalence classes as A002828. That is, for all i, j: a(i) = a(j) <=> A002828(i) = A002828(j). To get A002828 replace 0's with 3's, 3's with 1's and keep 2's as 2's and 4's as 4's.

Crossrefs

Programs

Formula

a(n) = 4*A072401(n) + 2*A229062(n) + A010052(n).

A002828 Least number of squares that add up to n.

Original entry on oeis.org

0, 1, 2, 3, 1, 2, 3, 4, 2, 1, 2, 3, 3, 2, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4, 3, 1, 2, 3, 4, 2, 3, 4, 2, 3, 2, 3, 1, 2, 3, 4, 2, 2, 3, 3, 3, 2, 3, 4, 3, 1, 2, 3, 2, 2, 3, 4, 3, 3, 2, 3, 4, 2, 3, 4, 1, 2, 3, 3, 2, 3, 3, 4, 2, 2, 2, 3, 3, 3, 3, 4, 2, 1, 2, 3, 3, 2, 3, 4, 3, 2, 2, 3, 4, 3, 3, 4, 3, 2, 2, 3, 1, 2, 3, 4, 2, 3
Offset: 0

Views

Author

Keywords

Comments

Lagrange's "Four Squares theorem" states that a(n) <= 4.
It is easy to show that this is also the least number of squares that add up to n^3.
a(n) is the number of iterations in f(...f(f(n))...) to reach 0, where f(n) = A262678(n) = n - A262689(n)^2. Allows computation of this sequence without Lagrange's theorem. - Antti Karttunen, Sep 09 2016
It is also easy to show that a(k^2*n) = a(n) for k > 0: Clearly a(k^2*n) <= a(n) but for all 4 cases of a(n) there is no k which would result in a(k^2*n) < a(n). - Peter Schorn, Sep 06 2021

References

  • N. J. A. Sloane, A Handbook of Integer Sequences, Academic Press, 1973 (includes this sequence).
  • N. J. A. Sloane and Simon Plouffe, The Encyclopedia of Integer Sequences, Academic Press, 1995 (includes this sequence).

Crossrefs

Programs

  • Haskell
    a002828 0 = 0  -- confessedly  /= 1, as sum [] == 0
    a002828 n | a010052 n == 1 = 1
              | a025426 n > 0 = 2 | a025427 n > 0 = 3 | otherwise = 4
    -- Reinhard Zumkeller, Feb 26 2015
    
  • Maple
    with(transforms);
    sq:=[seq(n^2, n=1..20)];
    LAGRANGE(sq,4,120);
    # alternative:
    f:= proc(n) local F,x;
       if issqr(n) then return 1 fi;
       if nops(select(t -> t[1] mod 4 = 3 and t[2]::odd, ifactors(n)[2])) = 0 then return 2 fi;
       x:= n/4^floor(padic:-ordp(n,2)/2);
       if x mod 8 = 7 then 4 else 3 fi
    end proc:
    0, seq(f(n),n=1..200); # Robert Israel, Jun 14 2016
    # next Maple program:
    b:= proc(n, i) option remember; convert(series(`if`(n=0, 1, `if`(i<1, 0,
          b(n, i-1)+(s-> `if`(s>n, 0, x*b(n-s, i)))(i^2))), x, 5), polynom)
        end:
    a:= n-> ldegree(b(n, isqrt(n))):
    seq(a(n), n=0..105);  # Alois P. Heinz, Oct 30 2021
  • Mathematica
    SquareCnt[n_] := If[SquaresR[1, n] > 0, 1, If[SquaresR[2, n] > 0, 2, If[SquaresR[3, n] > 0, 3, 4]]]; Table[SquareCnt[n], {n, 150}] (* T. D. Noe, Apr 01 2011 *)
    sc[n_]:=Module[{s=SquaresR[Range[4],n]},If[First[s]>0,1,Length[ First[ Split[ s]]]+1]]; Join[{0},Array[sc,110]] (* Harvey P. Dale, May 21 2014 *)
  • PARI
    istwo(n:int)=my(f);if(n<3,return(n>=0););f=factor(n>>valuation(n, 2)); for(i=1,#f[,1],if(bitand(f[i,2],1)==1&&bitand(f[i,1],3)==3, return(0)));1
    isthree(n:int)=my(tmp=valuation(n,2));bitand(tmp,1)||bitand(n>>tmp,7)!=7
    a(n)=if(isthree(n), if(issquare(n), !!n, 3-istwo(n)), 4) \\ Charles R Greathouse IV, Jul 19 2011, revised Mar 17 2022
    
  • Python
    from sympy import factorint
    def A002828(n):
        if n == 0: return 0
        f = factorint(n).items()
        if not any(e&1 for p,e in f): return 1
        if all(p&3<3 or e&1^1 for p,e in f): return 2
        return 3+(((m:=(~n&n-1).bit_length())&1^1)&int((n>>m)&7==7)) # Chai Wah Wu, Aug 01 2023
    
  • Python
    from sympy.core.power import isqrt
    def A002828(n):
        dp = [-1] * (n + 1)
        dp[0] = 0
        for i in range(1, n + 1):
            S = []
            r = isqrt(i)
            for j in range(1, r + 1):
                S.append(1 + dp[i - (j**2)])
            dp[i] = min(S)
        return dp[-1] # Darío Clavijo, Apr 21 2025
  • Scheme
    ;; The first one follows Charles R Greathouse IV's PARI-code above:
    (define (A002828 n) (cond ((zero? n) n) ((= 1 (A010052 n)) 1) ((= 1 (A229062 n)) 2) (else (+ 3 (A072401 n)))))
    (define (A229062 n) (- 1 (A000035 (A260728 n))))
    ;; We can also compute this without relying on Lagrange's theorem. The following recursion-formula should be used together with the second Scheme-implementation of A262689 given in the Program section that entry:
    (definec (A002828 n) (if (zero? n) n (+ 1 (A002828 (- n (A000290 (A262689 n)))))))
    ;; Antti Karttunen, Sep 09 2016
    

Formula

From Antti Karttunen, Sep 09 2016: (Start)
a(0) = 0; and for n >= 1, if A010052(n) = 1 [when n is a square], a(n) = 1, otherwise, if A229062(n)=1, then a(n) = 2, otherwise a(n) = 3 + A072401(n). [After Charles R Greathouse IV's PARI program.]
a(0) = 0; for n >= 1, a(n) = 1 + a(n - A262689(n)^2), (see comments).
a(n) = A053610(n) - A062535(n).
(End)

Extensions

More terms from Arlin Anderson (starship1(AT)gmail.com)

A077773 Number of integers between n^2 and (n+1)^2 that are the sum of two squares; multiple representations are counted once.

Original entry on oeis.org

0, 1, 2, 2, 3, 4, 4, 5, 6, 6, 7, 6, 9, 8, 8, 10, 10, 11, 11, 12, 11, 14, 12, 13, 15, 16, 15, 15, 17, 16, 17, 19, 18, 19, 20, 19, 20, 21, 20, 22, 22, 24, 22, 25, 23, 26, 26, 24, 29, 26, 27, 28, 27, 29, 26, 31, 32, 30, 29, 33, 33, 31, 31, 35, 34, 35, 35, 35, 36, 37, 37, 33, 42, 37, 38
Offset: 0

Views

Author

T. D. Noe, Nov 20 2002

Keywords

Comments

Related to the circle problem, cf. A077770. See A077774 for a more restrictive case. A077768 counts the representations multiply.
Number of integers k in range [n^2, ((n+1)^2)-1] for which 2 = the least number of squares that add up to k (A002828). Because of this interpretation a(0)=0 was prepended to the beginning. - Antti Karttunen, Oct 04 2016
This sequence is not surjective, since, for instance, there is no n such that a(n) = 46. This follows from a bound observed by Jon E. Schoenfield, that if a(n) = m then n < ((m+1)^2)/2, and the fact that a(n) != 46 for all n < 1105. - Rainer Rosenthal, Jul 25 2023

Examples

			a(8)=6 because 65=64+1=49+16, 68=64+4, 72=36+36, 73=64+9, 74=49+25 and 80=64+16 are between squares 64 and 81. Note that 65 is counted only once.
		

Crossrefs

Cf. A363762 (terms not occurring in this sequence), A363763.

Programs

  • Mathematica
    maxN=100; lst={}; For[n=1, n<=maxN, n++, sqrs={}; i=n; j=0; While[i>=j, j=1; While[i^2+j^2<(n+1)^2, If[i>=j&&i^2+j^2>n^2, AppendTo[sqrs, i^2+j^2]]; j++ ]; i--; j-- ]; AppendTo[lst, Length[Union[sqrs]]]]; lst
  • PARI
    a(N)=s=0;for(n=N^2+1,(N+1)^2-1,f=0;r=sqrtint(n);forstep(i=r,1,-1,if(issquare(n-i*i),f=1;s=s+1;break)));s /* Ralf Stephan, Sep 17 2013 */
    
  • Python
    from sympy import factorint
    def A077773(n): return sum(1 for m in range(n**2+1,(n+1)**2) if all(p==2 or p&3==1 or e&1^1 for p, e in factorint(m).items())) # Chai Wah Wu, Jun 20 2023
  • Scheme
    (define (A077773 n) (add (lambda (i) (* (- 1 (A010052 i)) (A229062 i))) (A000290 n) (+ -1 (A000290 (+ 1 n)))))
    ;; Implements sum_{i=lowlim..uplim} intfun(i)
    (define (add intfun lowlim uplim) (let sumloop ((i lowlim) (res 0)) (cond ((> i uplim) res) (else (sumloop (1+ i) (+ res (intfun i)))))))
    ;; Antti Karttunen, Oct 04 2016
    

Formula

a(n) = Sum_{i=n^2+1..(n+1)^2-1} A229062(i). - Ralf Stephan, Sep 17 2013
From Antti Karttunen, Oct 04 2016: (Start)
For n >= 0, a(n) + A277193(n) + A277194(n) = 2n.
For n >= 1, A277192(n) = a(n) + A277194(n). (End)

Extensions

Term a(0)=0 prepended by Antti Karttunen, Oct 04 2016

A260728 Bitwise-OR of the exponents of all 4k+3 primes in the prime factorization of n.

Original entry on oeis.org

0, 0, 0, 1, 0, 0, 1, 1, 0, 2, 0, 1, 1, 0, 1, 1, 0, 0, 2, 1, 0, 1, 1, 1, 1, 0, 0, 3, 1, 0, 1, 1, 0, 1, 0, 1, 2, 0, 1, 1, 0, 0, 1, 1, 1, 2, 1, 1, 1, 2, 0, 1, 0, 0, 3, 1, 1, 1, 0, 1, 1, 0, 1, 3, 0, 0, 1, 1, 0, 1, 1, 1, 2, 0, 0, 1, 1, 1, 1, 1, 0, 4, 0, 1, 1, 0, 1, 1, 1, 0, 2, 1, 1, 1, 1, 1, 1, 0, 2, 3, 0, 0, 1, 1, 0, 1, 0, 1, 3, 0, 1, 1, 1, 0, 1, 1, 0, 2, 1, 1, 1
Offset: 0

Views

Author

Antti Karttunen, Aug 12 2015

Keywords

Comments

A001481 (numbers that are the sum of 2 squares) gives the positions of even terms in this sequence, while its complement A022544 (numbers that are not the sum of 2 squares) gives the positions of odd terms.
If instead of bitwise-oring (A003986) we added in ordinary way the exponents of 4k+3 primes together, we would get the sequence A065339. For the positions where these two sequences differ see A260730.

Examples

			For n = 21 = 3^1 * 7^1 we compute A003986(1,1) = 1, thus a(21) = 1.
For n = 63 = 3^2 * 7^1 we compute A003986(2,1) = A003986(1,2) = 3, thus a(63) = 3.
		

Crossrefs

Cf. also A267113, A267116, A267099.
Differs from A065339 for the first time at n=21, where a(21) = 1, while A065339(21)=2.

Programs

Formula

If n < 3, a(n) = 0; thereafter, for any even n: a(n) = a(n/2), for any n with its smallest prime factor (A020639) of the form 4k+1: a(n) = a(A032742(n)), otherwise [when A020639(n) is of the form 4k+3] a(n) = A003986(A067029(n),a(A028234(n))).
Other identities. For all n >= 0:
A229062(n) = 1 - A000035(a(n)). [Reduced modulo 2 and complemented, the sequence gives the characteristic function of A001481.]
a(n) = a(A097706(n)). [The result depends only on the prime factors of the form 4k+3.]
a(n) = A267116(A097706(n)).
a(n) = A267113(A267099(n)).

A277193 Number of integers k in range [n^2, ((n+1)^2)-1] for which 3 = the least number of squares that add up to k (A002828).

Original entry on oeis.org

0, 1, 1, 3, 4, 4, 6, 6, 8, 9, 9, 12, 11, 14, 15, 14, 17, 18, 19, 19, 23, 20, 24, 25, 25, 26, 29, 29, 30, 32, 32, 32, 36, 36, 37, 39, 41, 40, 42, 43, 45, 45, 47, 46, 50, 49, 50, 54, 52, 55, 56, 57, 60, 60, 63, 60, 62, 65, 68, 64, 67, 70, 72, 69, 73, 74, 75, 76, 78, 78, 80, 84, 79, 85, 84, 84, 88, 89, 90, 90, 91, 94, 94, 97, 94, 99
Offset: 0

Views

Author

Antti Karttunen, Oct 04 2016

Keywords

Crossrefs

After the initial zero, one less than A277191.

Programs

  • Scheme
    (define (A277193 n) (add (lambda (i) (* (- 1 (A010052 i)) (- 1 (A229062 i)) (- 1 (A072401 i)))) (A000290 n) (+ -1 (A000290 (+ 1 n)))))
    ;; Implements sum_{i=lowlim..uplim} intfun(i)
    (define (add intfun lowlim uplim) (let sumloop ((i lowlim) (res 0)) (cond ((> i uplim) res) (else (sumloop (1+ i) (+ res (intfun i)))))))

Formula

Sum_{i=n^2 .. ((n+1)^2)-1} (1-A010052(i))*(1-A229062(i))*(1-A072401(i)).
Other identities. For all n >= 0:
1 + A077773(n) + a(n) + A277194(n) = 2n+1.
For n >= 1, a(n) = A277191(n)-1.

A277194 Number of integers k in range [n^2, ((n+1)^2)-1] for which 4 = the least number of squares that add up to k (A002828).

Original entry on oeis.org

0, 0, 1, 1, 1, 2, 2, 3, 2, 3, 4, 4, 4, 4, 5, 6, 5, 5, 6, 7, 6, 8, 8, 8, 8, 8, 8, 10, 9, 10, 11, 11, 10, 11, 11, 12, 11, 13, 14, 13, 13, 13, 15, 15, 15, 15, 16, 16, 15, 17, 17, 17, 17, 17, 19, 19, 18, 19, 19, 21, 20, 21, 21, 22, 21, 21, 22, 23, 22, 23, 23, 25, 23, 24, 26, 25, 26, 26, 26, 27, 26, 27, 27, 28, 29, 28, 29, 30, 29, 30, 30, 31
Offset: 0

Views

Author

Antti Karttunen, Oct 04 2016

Keywords

Crossrefs

Programs

  • Scheme
    (define (A277194 n) (add A072401 (A000290 n) (+ -1 (A000290 (+ 1 n)))))
    ;; Implements sum_{i=lowlim..uplim} intfun(i)
    (define (add intfun lowlim uplim) (let sumloop ((i lowlim) (res 0)) (cond ((> i uplim) res) (else (sumloop (1+ i) (+ res (intfun i)))))))

Formula

a(n) = Sum_{i=n^2 .. ((n+1)^2)-1} A072401(i).
Other identities.
For n >= 0, 1 + A077773(n) + A277193(n) + a(n) = 2n+1.
For n >= 1, A277192(n) = A077773(n) + a(n).

A102548 Number of positive integers <= n that are expressible in the form u^2+v^2, with u and v integers.

Original entry on oeis.org

1, 2, 2, 3, 4, 4, 4, 5, 6, 7, 7, 7, 8, 8, 8, 9, 10, 11, 11, 12, 12, 12, 12, 12, 13, 14, 14, 14, 15, 15, 15, 16, 16, 17, 17, 18, 19, 19, 19, 20, 21, 21, 21, 21, 22, 22, 22, 22, 23, 24, 24, 25, 26, 26, 26, 26, 26, 27, 27, 27, 28, 28, 28, 29, 30, 30, 30, 31, 31, 31, 31, 32, 33, 34, 34
Offset: 1

Views

Author

Salvador Perez Gomez (pies314(AT)hotmail.com), Feb 24 2005

Keywords

Examples

			a(8) = 5 because 1 = 0^2 + 1^2, 2 = 1^2 + 1^2, 4 = 0^2 + 2^2, 5 = 1^2 + 2^2, 8 = 2^2 + 2^2, but 3,6 and 7 are not of the form u^2 + v^2, with u and v integers.
		

Crossrefs

Programs

  • Maple
    a := proc(n) local aux,i,m,u,v; aux:=0; for i from 1 to n do m:=floor(sqrt(i/2)); for u from 0 to m do v:=sqrt(i-u^2); if (v = floor(v)) then aux:=aux+1; u:=m; end if; end do; end do; aux; end proc:
  • Mathematica
    a[1]=1; a[n_]:= a[n]= a[n-1] + If[SquaresR[2, n]>0, 1, 0]; Table[a[n], {n,75}] (* Jean-François Alcover, Mar 31 2015 *)
  • PARI
    first(n)= my(v = vector(n + 1), res = vector(n)); res[1] = 1; for(i = 0, sqrtint(n), for(j = i, sqrtint(n - i^2), v[i^2+j^2+1] = 1 ) ); for(i = 2, #res, res[i] = res[i-1] + v[i+1]; ); res \\ David A. Corneth, Jun 05 2020
    
  • Python
    from itertools import count, accumulate, islice
    from sympy import factorint
    def A102548_gen(): # generator of terms
        return accumulate(int(all(p & 3 != 3 or e & 1 == 0 for p, e in factorint(n).items())) for n in count(1))
    A102548_list = list(islice(A102548_gen(),30)) # Chai Wah Wu, Jun 28 2022

Formula

From David A. Corneth, Jun 05 2020: (Start)
A000161(a(n)) > 0.
a(n) = (partial sum of A229062 up to n) - 1. (End)
a(n) = n/sqrt(log n) * (K + B2/log n + O(1/log^2 n)), where K = A064533 and B2 = A227158. In particular, a(n) ~ Kn/sqrt(log n). - Charles R Greathouse IV, Dec 03 2022

Extensions

Name clarified by David A. Corneth, Jun 05 2020
Showing 1-7 of 7 results.