连续的自然数平方和


3 4 5 3^2+4^2=5^2
10 11 12 13 14 10^2+11^2+12^2=13^2+14^2
左边n+1个右边n个自然数
question:输入一个数n(1<=n<=1000)判断是否存在2*n+1个连续的自然数满足上式
设中间数字为x
(x-n)^2+(x-n+1)^2+...+x^2=(x+1)^2+...+(x+n)^2
二项式展开
x=2*n*(n+1)中间元素
只需向前向后分别找n个元素,即题解


啦啦啦,数学使问题变得简单~~~

 1 #include "iostream"
 2 #include "cstdio"
 3 using namespace std;
 4 int main()
 5 {
 6     int n;
 7     while(~scanf("%d",&n)&&n)
 8     {
 9         int Begin=2*n*(n+1)-n;
10         int End=2*n*(n+1)+n;
11         for(int i=Begin;i<=End;i++)
12             printf("%d ",i);
13         printf("\n");
14     }
15     return 0;
16 }

 

posted @ 2017-02-13 22:32  kimsimple  阅读(509)  评论(0编辑  收藏  举报