-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1780.cpp
More file actions
43 lines (38 loc) · 751 Bytes
/
1780.cpp
File metadata and controls
43 lines (38 loc) · 751 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
#include<iostream>
#include<cmath>
bool checkPowersOfThree(int n) {
int i = 0;
int sum = 0;
while(true) {
int a = std::pow(3, i);
if(a >= n) {
start:
if(i < 0) {
break;
}
int b = std::pow(3, i);
sum += b;
if(sum == n) {
return true;
}
else if(sum > n) {
sum -= b;
--i;
goto start;
}
else {
--i;
goto start;
}
}
else {
++i;
}
}
return false;
}
int main() {
int n = 91;
std::cout << checkPowersOfThree(n);
std::cin.get();
}