forked from sunnyshahabuddin/Coding-Ninjas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPanda_And_Numbers.cpp
55 lines (54 loc) · 978 Bytes
/
Panda_And_Numbers.cpp
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define shazam ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define M 1000000007
using namespace std;
bool mark[1000001];
bool vis[1000001];
void ins(ll num)
{
vis[num] = true;
set<ll>distinct;
distinct.clear();
ll x = num;
while (x > 0)
{
distinct.insert(x % 10);
x /= 10;
}
bool ans = false;
for (auto it = distinct.begin(); it != distinct.end(); it++)
{
if((num - ((*it) * (*it)))>0)
ans |= mark[(num - ((*it) * (*it)))];
if (ans) {break;}
}
mark[num] = ans;
}
int main()
{
shazam;
ll i, t, n, m, x, k, y, j, l, r, z;
memset(mark, false, sizeof(mark));
memset(vis, false, sizeof(vis));
for (i = 1; i <= 7; i++) {mark[(ll)pow(i, i)] = true; vis[(ll)pow(i, i)] = true;}
for (i = 1; i <= 1000000; i++)
{
if (!vis[i])
ins(i);
}
cin >> t;
while (t--)
{
cin >> n;
if (mark[n])
{
cout << "Yes\n";
}
else
{
cout << "No\n";
}
}
}