-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCPP0139.cpp
More file actions
56 lines (51 loc) · 975 Bytes
/
Copy pathCPP0139.cpp
File metadata and controls
56 lines (51 loc) · 975 Bytes
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
56
#include <bits/stdc++.h>
#define MOD 1000000007
#define MAX 10000001
#define ll long long
using namespace std;
int tongcs(int n) {
int tong = 0;
while (n) {
tong += n % 10;
n /= 10;
}
return tong;
}
bool prime(int n) {
for (int i = 2; i <= sqrt(n); i++) {
if (n % i == 0)
return 0;
}
return n > 1;
}
bool smith(int n) {
if (prime(n))
return 0;
int temp = tongcs(n);
int tong = 0;
for (int i = 2; i <= sqrt(n); i++) {
while (n % i == 0) {
tong += tongcs(i);
n /= i;
}
}
if (n != 1)
tong += tongcs(n);
if (temp == tong)
return 1;
else
return 0;
}
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
if (smith(n))
cout << "YES\n";
else
cout << "NO\n";
}
return 0;
}