Advertisement
Spocoman

08. Strong Number

Nov 2nd, 2023
586
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.46 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.     string strong;
  8.     cin >> strong;
  9.  
  10.     int number = stoi(strong), sum = 0;
  11.  
  12.     for (int i = 1; i <= strong.length(); i++) {
  13.         int factorial = 1;
  14.         for (int j = 1; j <= number % 10; j++) {
  15.             factorial *= j;
  16.         }
  17.         sum += factorial;
  18.         number /= 10;
  19.     }
  20.  
  21.     cout << (stoi(strong) == sum ? "yes" : "no") << endl;
  22.     return 0;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement