Advertisement
dimuster

дз 20.10

Oct 20th, 2022
1,154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.24 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     srand(time(0));
  7.     int n = 20;
  8.     vector<int> a1(n), a2(n), a3(n); // №1
  9.     vector<int> b1, b2; // №2
  10.     for (int i = 0; i < n; i++) {
  11. //        cin >> a1[i];
  12.         a1[i] = rand() % (99 - 10 + 1) + 10; // [10; 99]
  13.         cout << a1[i] << " ";
  14.     }
  15.     cout << "\n";
  16.     for (int i = 0; i < n; i++) {
  17.         int x = a1[i], k = 0, s = 0;
  18.         for (int d = 2; d * d <= x; d++) {
  19.             if (x % d == 0) {
  20.                 k++;
  21.                 s += d;
  22.                 if (x / d != d) {
  23.                     k++;
  24.                     s += x / d;
  25.                 }
  26.             }
  27.         }
  28.         if (s % 2 == 1) {
  29.             b1.push_back(a1[i]);
  30.         } else {
  31.             b2.push_back(a1[i]);
  32.         }
  33.         a2[i] = s;
  34.         a3[i] = k;
  35.     }
  36.    
  37.     for (int i = 0; i < n; i++) {
  38.         cout << a2[i] << " ";
  39.     }
  40.     cout << "\n";
  41.     for (int i = 0; i < n; i++) {
  42.         cout << a3[i] << " ";
  43.     }
  44.     cout << "\n\n\n";
  45.    
  46.     for (int i = 0; i < b1.size(); i++) {
  47.         cout << b1[i] << " ";
  48.     }
  49.     cout << "\n";
  50.     for (int i = 0; i < b2.size(); i++) {
  51.         cout << b2[i] << " ";
  52.     }
  53.    
  54.     return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement