Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Ask questions, find answers and collaborate at work with Stack Overflow for Teams.
Ask questions, find answers and collaborate at work with Stack Overflow for Teams. Explore Teams
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
N=>eval('for(k=0,n=1;n<=N;n++k=n=0;n++<N;)for(c=e=N%n||n;c<=e+N-n;k+=c*c++n;);k'k+=c*c++')
Try it online!Try it online!
-2 by Polichinelle.
Iteratively calculates sum, which is shorter than direct calculation.
N=>eval('for(k=0,n=1;n<=N;n++)for(c=e=N%n||n;c<=e+N-n;k+=c*c++);k')
Try it online!
N=>eval('for(k=n=0;n++<N;)for(c=e=N%n||n;c<=e+N-n;)k+=c*c++')
N=>eval('for(k=n=0;n<N;c=N%++n||n,d=c+N-nk=0,k+=d*-~d*(d-~dn=1;n<=N;n++)-~-c*c*for(c+cc=e=N%n||n;c<=e+N-1)n;k+=c*c++);k/6';k')
-1 by @KevinCruijssenTry it online!
DirectlyIteratively calculates the sum for each n, ratherwhich is shorter than iteratively doing sodirect calculation.
n
N=>eval('for(k=n=0;n<N;c=N%++n||n,d=c+N-n,k+=d*-~d*(d-~d)-~-c*c*(c+c-1));k/6')
-1 by @KevinCruijssen
Directly calculates the sum for each n, rather than iteratively doing so.
N=>eval('for(k=n=0;n<N;c=N%++n||n,d=c+N-n,k+=d*-~d*(d+d+1d-~d)-~-c*c*(c+c-1));k/6')
N=>eval('for(k=n=0;n<N;c=N%++n||n,d=c+N-n,k+=d*-~d*(d+d+1)-~-c*c*(c+c-1));k/6')