๐Ÿ“ฆ ved015 / Codeforces-solution

๐Ÿ“„ rudolfandsnowflakes1300.cpp ยท 29 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29#include<iostream>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
int main(){
    int t;
    cin >> t;
    while(t--){
        int sum;
        cin >> sum;
        bool flag = false;
        for(int k = 2; k < 1000; k++){
            for(int n = 3; n < 20; n++){
                long long tot = pow(k,n) - 1;
                if(tot > sum*(k-1)) break;
                
                tot = tot/(k-1);
                if(tot == sum){
                    flag = true;
                }
            }
            if(flag) break;
        }
        if(flag) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}