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. srand(time(0));
  17. int step = 0;
  18. string best;
  19. for (int i = 5; i <= 50; ++i) {
  20. for (int j = 1; j <= 1000; ++j) {
  21. string s = "";
  22. for (int k = 0; k < i; ++k) {
  23. int x = rand() % 9 + 1;
  24. s += to_string(x);
  25. }
  26. string tmp = s;
  27. int li = 0;
  28. while (tmp.size() > 1) {
  29. tmp = next(tmp);
  30. ++li;
  31. }
  32. if (li > step) {
  33. step = li;
  34. best = s;
  35. }
  36. }
  37. }
  38. cout << best << "\n";
  39. cout << step << "\n";
  40. }
  41.  
Success #stdin #stdout 0.15s 5320KB
stdin
Standard input is empty
stdout
39786878629
10