2016 7th Blue Bridge Cup CC++ Program Design Undergraduate Group B Provincial Competition Birthday Candle (Fill in the blank)

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)
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
		sum = 0;
	return 0;


It can also be combined with the summation formula of arithmetic progression!

Guess you like