Advertisement
Infiniti_Inter

For Alisa 89 1 (6)

May 14th, 2019
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <windows.h>
  5.  
  6. using namespace std;
  7.  
  8.  
  9. bool isSimple(int n)
  10. {
  11.     if (n == 1)// 1 это не простое число
  12.         return false;
  13.     for (int i = 2; i * i <= n; ++i)
  14.         if (n % i == 0)
  15.             return false;
  16.     return true;
  17. }
  18.  
  19. int main()
  20. {
  21.     int x;
  22.     cout << "X = ";
  23.     cin >> x;
  24.     int n;
  25.     cout << "N = ";
  26.     cin >> n;
  27.     vector<int> a(n);
  28.     for (int i = 0; i < n; ++i)
  29.         {
  30.             cin >> a[i];
  31.             if (isSimple(a[i]))
  32.                 a[i] = x;
  33.         }
  34.     for (int i = 0; i < n; ++i)
  35.         cout << a[i] << ' ';
  36.     system("pause");
  37.  
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement