fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. bool check(string s){
  4. for(char c:s)
  5. if (c=='0') return true;
  6. return false;
  7. }
  8. string next(string s){
  9. if (check(s)) return "0";
  10. long long tich = 1;
  11. for (char c:s)
  12. tich *=(c -'0');
  13. return to_string(tich);
  14. }
  15. int main(){
  16. ios_base::sync_with_stdio(false);
  17. cin.tie(NULL);
  18. int ans = 0;
  19. string maxi;
  20. for (int i = 1; i <= 50; ++i){
  21. for (int j = 1; j <= 1000; ++j){
  22. string s = "";
  23. for (int k = 0; k < i; ++k){
  24. int x = rand() % 9 + 1;
  25. s += to_string(x);
  26. }
  27. string tmp = s;
  28. int li = 0;
  29. while (tmp.size() > 1){
  30. tmp = next(tmp);
  31. ++li;
  32. }
  33. if (li >ans){
  34. ans = li;
  35. maxi = s;
  36. }
  37. }
  38. }
  39. cout << maxi << "\n";
  40. cout << ans << "\n";
  41. }
  42.  
Success #stdin #stdout 0.15s 5320KB
stdin
Standard input is empty
stdout
73686887299
10