SPOJ Problem 3410:Feynman
水题,求1到n的平方和,直接代公式x=(1/6)*n*(n+1)*(2*n+1)
#include<cstdio> #include<cstring> int main(){ int n,x; while(scanf("%d",&x)&&x){ printf("%d\n",x*(x+1)*(2*x+1)/6); } }
posted on 2015-03-03 20:03 problemcutter 阅读(94) 评论(0) 收藏 举报
水题,求1到n的平方和,直接代公式x=(1/6)*n*(n+1)*(2*n+1)
#include<cstdio> #include<cstring> int main(){ int n,x; while(scanf("%d",&x)&&x){ printf("%d\n",x*(x+1)*(2*x+1)/6); } }
posted on 2015-03-03 20:03 problemcutter 阅读(94) 评论(0) 收藏 举报