Advertisement
Guest User

Untitled

a guest
Feb 20th, 2020
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. #include <fstream>
  2. #include <iostream>
  3. using namespace std;
  4. bool search(int digit);
  5. int main()
  6. {
  7. ifstream fin("INPUT.TXT");
  8. ofstream fout("OUTPUT.TXT");
  9. int digit;
  10. cin >> digit;
  11. int idigit = digit;
  12. int k = 0;
  13. while (digit > 0)
  14. {
  15. k++;
  16. digit /= 10;
  17. }
  18. int *Array = new int[k];
  19. for (size_t i = 0; i < k; i++)
  20. {
  21. if (idigit % 10 == 0)
  22. {
  23. cout << "No";
  24. return 0;
  25. }
  26. *(Array + i) = idigit % 10;
  27. idigit /= 10;
  28. }
  29. int ten = k - 1, l = 0;
  30. for (size_t i = 1; i < 10; i++)
  31. {
  32. for (size_t j = 0; j < k; j++)
  33. {
  34. if (*(Array + j) == i)
  35. {
  36. digit = digit + i*pow(10, ten);
  37. if (l == 0 && i % 2 == 0)
  38. {
  39. cout << "No";
  40. return 0;
  41. }
  42. idigit = idigit + i*pow(10, l);
  43. l++;
  44. ten--;
  45. }
  46. }
  47.  
  48. }
  49.  
  50. if (search(digit) == true)
  51. {
  52. cout << "No";
  53. }
  54. else
  55. {
  56.  
  57. if (search(idigit) == true)
  58. {
  59. cout << "No";
  60. }
  61. else
  62. {
  63. cout << "Yes";
  64. }
  65. }
  66. fin.close();
  67. fout.close();
  68. return 0;
  69. }
  70.  
  71. bool search(int digit)
  72. {
  73. int k = 0;
  74. for (int i = 2; i <= digit/2; i++)
  75. {
  76. if (digit%i == 0)
  77. {
  78. return true;
  79. }
  80. }
  81. if (k == 0)
  82. {
  83. return false;
  84. }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement