fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. bool is_deg3(const int num) {
  5. int value = 1;
  6.  
  7. while (value < num) {
  8. value *= 3;
  9. }
  10.  
  11. return value == num;
  12. }
  13.  
  14. int main()
  15. {
  16. const int num = 1'870'418'611;
  17.  
  18. cout << std::boolalpha << is_deg3(num);
  19. return 0;
  20. }
Success #stdin #stdout 0s 4392KB
stdin
Standard input is empty
stdout
true