Description
LG家门口的小树林在近期的雷击事故中被毁灭殆尽
LG找来了p棵树苗准备重建小树林
这次的要求是“……这片树林中的树木可构成a个以这块标牌为圆心的同心圆,其中最靠近这块标牌的圆上有b棵树,其他圆上树木数量都是向内一层的圆上树木数量的b倍。……”
当然,a和b必须是大于1的整数
试问LG能否使这p棵树苗刚好用完
Input
一个整数 10<=p<=10000000
Output
如果可以刚好用完,用单独一行输出
YES
否则用单独一行输出
NO
Sample Input
1110
Sample Output
YES
Hint
样例当a=3,b=10的时候可以将1110棵树苗刚好用完
分析:我没有想到的是,这么暴力,,,,,,
#include<stdio.h>
#include<iostream>
#include<map>
#include<algorithm>
#include<cstring>
#include<string.h>
#include<string>
#include<math.h>
#include<vector>
#include<map>
using namespace std;
//typedef long long ll;
#define MAXN 100005*8
#define INF 0x3f3f3f3f//将近int类型最大数的一半,而且乘2不会爆int
#define MOD 1000000007
int main()
{
int y;
cin >> y;
int flag = 0;
for (int i = (int)sqrt(y); i > 1; --i) {
for (int j = 2; j <= (int)sqrt(y); ++j) {
int sum = 0, ans = 1;
for (int k = 1; k <= j; ++k) {
ans *= i;
sum += ans;
}
if (sum == y) {
flag = 1;
break;
}
else if (sum > y) break;
}
if (flag) break;
}
if (flag) puts("YES");
else puts("NO");
//system("pause");
return 0;
}