当前位置:网站首页>As a result, fill in the birthday candles

As a result, fill in the birthday candles

2022-07-28 07:01:00 White mouse zero

From a certain year on, you hold a birthday every year party, And blow out the same number of candles with the same age every time .
Now count , He blew it out altogether 236 A candle .
Excuse me, , How old did he start celebrate sb 's birthday party Of ?

Please fill in his birthday party The age of .


answer

26


The problem solving process

It is very routine to use the formula of arithmetic sequence +for Problems that can be solved by circulation .


Attach code

#include<iostream>
using namespace std;
int main()
{
	void find();
	find();
	return 0;
}
void find()
{
	int sum=0;
	for(int i=1;i<=100;i++)
	{
		for(int j=100;j>i;j--)
		{
			sum=(i+j)*(j-i+1)/2;
			if(sum<236)
				break;
			if(sum==236)
			{
				cout<<i<<endl;
				return;
			}
		}
	}
}

 

原网站

版权声明
本文为[White mouse zero]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/209/202207280517191197.html