连续的自然数平方和


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 }

 

转载于:https://www.cnblogs.com/kimsimple/p/6390753.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值