fork(9) download
  1. #include <iostream>
  2. #include <stack>
  3.  
  4. using namespace std;
  5.  
  6. void solution(int n)
  7. {
  8. if (n < 0) {
  9. cout << "NIE";
  10. }
  11. else {
  12. if (n >= 0 && n <= 9) {
  13. cout << 1 << n;
  14. }
  15. else {
  16. stack<int> digits;
  17.  
  18. for (int i = 9; i >= 2 && n > 1; i--)
  19. {
  20. while (n % i == 0) {
  21. digits.push(i);
  22. n /= i;
  23. }
  24. }
  25.  
  26. if (n == 1) {
  27. long long int k = 0;
  28.  
  29. while (!digits.empty()) {
  30. k = k * 10 + digits.top();
  31. digits.pop();
  32. }
  33.  
  34. cout << k;
  35. }
  36. else {
  37. cout << "NIE";
  38. }
  39. }
  40. }
  41. }
  42.  
  43. int main(){
  44. ios_base::sync_with_stdio(false);
  45. cin.tie(NULL);
  46.  
  47. int t;
  48. long int n;
  49. stack<int> digits;
  50.  
  51. cin >> t;
  52.  
  53. while(t--) {
  54. cin >> n;
  55. solution(n);
  56. if(t > 0) {
  57. cout << "\n";
  58. }
  59. }
  60.  
  61. return 0;
  62. }
  63.  
Success #stdin #stdout 0.01s 5516KB
stdin
14
15
20
0
1
2
3
4
9
200
1000
100000
1000000000
101
-10
stdout
35
45
10
11
12
13
14
19
558
5558
4555558
555555555888
NIE
NIE