Skip to main content
replaced http://codegolf.stackexchange.com/ with https://codegolf.stackexchange.com/
Source Link

Python (59 57 56 bytes)

lambda n:0**n+sum((-(n%(x-~x)<1))**x*4for x in range(n))

Online demo

As with my CJam answer, this uses Möbius inversion and runs in pseudoquasilinear time.

Thanks to Sp3000Sp3000 for 2 bytes' savings, and feersumfeersum for 1.

Python (59 57 56 bytes)

lambda n:0**n+sum((-(n%(x-~x)<1))**x*4for x in range(n))

Online demo

As with my CJam answer, this uses Möbius inversion and runs in pseudoquasilinear time.

Thanks to Sp3000 for 2 bytes' savings, and feersum for 1.

Python (59 57 56 bytes)

lambda n:0**n+sum((-(n%(x-~x)<1))**x*4for x in range(n))

Online demo

As with my CJam answer, this uses Möbius inversion and runs in pseudoquasilinear time.

Thanks to Sp3000 for 2 bytes' savings, and feersum for 1.

added 78 characters in body
Source Link
Peter Taylor
  • 43.1k
  • 4
  • 70
  • 169

Python (59 57 5756 bytes)

lambda n:0**n+4*sum0**n+sum((-(n%(x-~x)<1))**x for**x*4for x in range(n))

Online demoOnline demo

As with my CJam answer, this uses Möbius inversion and runs in pseudoquasilinear time.

Thanks to Sp3000 for 2 bytes' savings, and feersum for 1.

Python (59 57 bytes)

lambda n:0**n+4*sum((-(n%(x-~x)<1))**x for x in range(n))

Online demo

As with my CJam answer, this uses Möbius inversion and runs in pseudoquasilinear time.

Thanks to Sp3000 for 2 bytes' savings.

Python (59 57 56 bytes)

lambda n:0**n+sum((-(n%(x-~x)<1))**x*4for x in range(n))

Online demo

As with my CJam answer, this uses Möbius inversion and runs in pseudoquasilinear time.

Thanks to Sp3000 for 2 bytes' savings, and feersum for 1.

Bounty Ended with 100 reputation awarded by xnor
added 116 characters in body
Source Link
Peter Taylor
  • 43.1k
  • 4
  • 70
  • 169

Python (5959 57 bytes)

lambda n:(n<1)+4*sum0**n+4*sum((-(n%(2*x+1x-~x)<1))**x for x in range(n))

Online demo

As with my CJam answer, this uses Möbius inversion and runs in pseudoquasilinear time.

Thanks to Sp3000 for 2 bytes' savings.

Python (59 bytes)

lambda n:(n<1)+4*sum((-(n%(2*x+1)<1))**x for x in range(n))

Online demo

As with my CJam answer, this uses Möbius inversion and runs in pseudoquasilinear time.

Python (59 57 bytes)

lambda n:0**n+4*sum((-(n%(x-~x)<1))**x for x in range(n))

Online demo

As with my CJam answer, this uses Möbius inversion and runs in pseudoquasilinear time.

Thanks to Sp3000 for 2 bytes' savings.

Add online demo
Source Link
Peter Taylor
  • 43.1k
  • 4
  • 70
  • 169
Loading
Source Link
Peter Taylor
  • 43.1k
  • 4
  • 70
  • 169
Loading