蓝桥杯第七届省赛C语言B组第二题生日蜡烛解题报告---暴力

版权声明:转载请注明出处:https://blog.csdn.net/qq1013459920 https://blog.csdn.net/qq1013459920/article/details/88376820

                                                生日蜡烛

某君从某年开始每年都举办一次生日party,并且每次都要吹熄与年龄相同根数的蜡烛。

现在算起来,他一共吹熄了236根蜡烛。

请问,他从多少岁开始过生日party的?

请填写他开始过生日party的年龄数。
注意:你提交的应该是一个整数,不要填写任何多余的内容或说明性文字。

答案:26

Code: 

#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <map>
#include <iostream>
using namespace std;
typedef long long ll;
int main(){
	for (int n = 1; n <= 100; ++n) {
		for (int a1 = 1; a1 <= 100; ++a1) {
			if (n * (2 * a1 + n - 1) / 2 == 236) {
				printf("%d\n", a1);
			}
		}
	}
	return 0;
}


 

猜你喜欢

转载自blog.csdn.net/qq1013459920/article/details/88376820