fork download
  1. #include <iostream>
  2. #include <map>
  3. #include <vector>
  4. #include <queue>
  5. using namespace std;
  6. string fun(string s , int n) {
  7. if (s.size() == 1 && n == 1) {
  8. return s;
  9. }
  10. long long sm = 0;
  11. for (int i = 0; i < s.size(); i++) {
  12. sm += s[i] - '0';
  13. }
  14. sm *= n;
  15. return fun(to_string(sm) , 1);
  16. }
  17. int main() {
  18. ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  19. string s;
  20. int n;
  21. cin >> s >> n;
  22. cout << fun(s , n);
  23.  
  24. }
  25.  
Success #stdin #stdout 0s 5288KB
stdin
148 3
stdout
3