Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cmath>
  4.  
  5. using namespace std;
  6.  
  7. long int fact(int N){
  8. if (N < 0)
  9. return 0;
  10. if (N == 0)
  11. return 1;
  12. else
  13. return N * fact(N - 1);
  14. }
  15.  
  16. void check(int n, int& N) {
  17. int B[10] = { 0 };
  18. while (n > 0) {
  19. B[n % 10]++;
  20. n /= 10;
  21. }
  22. for (int i = 0; i < 10; i++) {
  23. if (B[i] > 1) {
  24. N--;
  25. }
  26. }
  27. }
  28.  
  29. bool Num(int N){
  30. int p, sum;
  31. p = 1;
  32. sum = 0;
  33. while (N > 0)
  34. {
  35. sum += N % 10;
  36. p *= N % 10;
  37. N /= 10;
  38. }
  39. if (p == sum)
  40. return true;
  41. return false;
  42. }
  43.  
  44. int main()
  45. {
  46. ifstream fin("INPUT.txt");
  47.  
  48. int N = 0, k = 0;
  49. long long num = 0, b = 0, i = 0;
  50.  
  51. fin >> N;
  52. fin.close();
  53.  
  54. ofstream fout("OUTPUT.txt");
  55. if (N == 1)
  56. fout << 10 << " " << 0;
  57. else
  58. {
  59. i = pow(10, N - 1);
  60. b = pow(10, N);
  61. while ((k == 0) && (i < b)) {
  62. if (Num(i)){
  63. check(i, N);
  64. k = fact(N);
  65. num = i;
  66. }
  67. ++i;
  68. }
  69. fout << k << " " << num;
  70. }
  71. fout.close();
  72.  
  73. return 0;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement