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