fork download
  1. #include <iostream>
  2. #include <cstdint>
  3.  
  4. typedef int_fast64_t Int;
  5. const Int FAILURE = -1;
  6.  
  7. Int zagadka(int x) {
  8. if (x < 10) return x;
  9.  
  10. unsigned n = x;
  11. int counters[10] = { 0 };
  12. for (int i = 9; i >= 2; i--) {
  13. while (n % i == 0) {
  14. n /= i;
  15. counters[i] += 1;
  16. }
  17. }
  18.  
  19. if (n > 1) return FAILURE;
  20.  
  21. Int acc = 0;
  22. for (Int i = 2; i < 10; i++) {
  23. for (int k = 0; k < counters[i]; k++) {
  24. acc = 10*acc + i;
  25. }
  26. }
  27. return acc;
  28. }
  29.  
  30. int main() {
  31. int n;
  32. while (std::cin >> n) {
  33. Int result = zagadka(n);
  34. if (result == FAILURE) {
  35. std::cout << "Rozwiazanie nie istnieje" << std::endl;
  36. } else {
  37. std::cout << result << std::endl;
  38. }
  39. }
  40. return 0;
  41. }
Success #stdin #stdout 0s 3344KB
stdin
1
2
9
10
11
72
1073741824
1000000000
244140625
stdout
1
2
9
25
Rozwiazanie nie istnieje
89
8888888888
555555555888
555555555555