Advertisement
DobriyKrot

Untitled

Aug 30th, 2022
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.13 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <cmath>
  4. #include <unordered_map>
  5. #include <map>
  6. #include <string>
  7. #include <cstdlib>
  8. #include <cctype>
  9. #include <algorithm>
  10. #include <set>
  11.  
  12. using namespace std;
  13.  
  14. // 25 15
  15. // НОД: 5 gcd(a, b)
  16. // НОК: 25 * 15 / 5 = 75
  17.  
  18. // 18: 18, 9, 6, 3, 2, 1
  19.  
  20. /*
  21.     a = x * y;
  22.     1) x == y, x == sqrt(a), y == sqrt(a)
  23.     16 = 4 * 4 == sqrt(a) * sqrt(a) == a
  24.    
  25.     2) x != y, x < y, x < sqrt(a), y > sqrt(a)
  26.    
  27.     28, sqrt(28) = 6
  28.    
  29.     1, 2, 4, 7, 14, 28
  30.    
  31.    
  32.     a == 10^9
  33.     O(a) ~ 10^10 ~ TL
  34.     O(sqrt(a)) ~ 10^5 ~ AC
  35. */
  36.  
  37.  
  38.  
  39. // 2, 3, 5, 7, 11, 13, 17, 19
  40. // 18 = 2 * 3 * 3
  41. // 9
  42. // 3
  43. // 1
  44.  
  45.  
  46.  
  47. int main()
  48. {
  49.     int a;
  50.     cin >> a;
  51.    
  52.     // Вывод всех делителей за линию.
  53.     for (int i = 0; i < a; ++i) { // O(a)
  54.         if (a % i == 0) {
  55.             cout << i << " ";
  56.         }
  57.     }
  58.    
  59.     // Вывод всех делителей за корень.
  60.     for (int i = 0; i * i <= a; ++i) { // O(sqrt(a))
  61.         if (a % i == 0) {
  62.             cout << i << " ";
  63.             if (a / i != i) {
  64.                 cout << a / i << " ";
  65.             }
  66.         }
  67.     }
  68.    
  69.     // Проверка на простоту.
  70.     int cnt = 0;
  71.     for (int i = 0; i * i <= a; ++i) { // O(sqrt(a))
  72.         if (a % i == 0) {
  73.             ++cnt;
  74.             if (a / i != i) {
  75.                 ++cnt;
  76.             }
  77.         }
  78.     }
  79.     if (cnt == 2) {
  80.         cout << "YES\n";
  81.     } else {
  82.         cout << "NO\n";
  83.     }
  84.    
  85.    
  86.     // Проверка на простоту.
  87.     bool flag = true;
  88.     for (int i = 2; i * i <= a; ++i) { // O(sqrt(a))
  89.         if (a % i == 0) {
  90.             cout << "NO";
  91.             flag = false;
  92.             break;
  93.         }
  94.     }
  95.     if (flag) {
  96.         cout << "YES";
  97.     }
  98.    
  99.        
  100.     // Факторизация числа за O(sqrt(a))
  101.     for (int i = 2; i * i <= a; ++i) {
  102.         while (a % i == 0) {
  103.             cout << i << ' ';
  104.             a /= i;
  105.         }
  106.     }    
  107.     if (a != 1) {
  108.         cout << a;
  109.     }
  110.    
  111.    
  112.    
  113.    
  114.     return 0;
  115. }
  116.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement