birthday candles
A certain gentleman has held a birthday party every year since a certain year, and every time he has to blow out the same number of candles as his age.
Now counting, he blew out a total of 236 candles.
Excuse me, at what age did he start birthday parties?
Please fill in the age at which he started his birthday party.
.
Method: while violence
Result: 26 (now 33)
#include<iostream> using namespace std; int main() { int sum = 0; int begin = 1; while (1) { int i = begin; while (sum <= 236) { sum += i; if (sum == 236) { cout << begin << endl; //cout <<i << endl;//Current age exit(0); } i++; } begin++; sum = 0; } return 0; }
.
.
It can also be combined with the summation formula of arithmetic progression!