Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <cmath>
- #include <unordered_map>
- #include <map>
- #include <string>
- #include <cstdlib>
- #include <cctype>
- #include <algorithm>
- #include <set>
- using namespace std;
- // 25 15
- // НОД: 5 gcd(a, b)
- // НОК: 25 * 15 / 5 = 75
- // 18: 18, 9, 6, 3, 2, 1
- /*
- a = x * y;
- 1) x == y, x == sqrt(a), y == sqrt(a)
- 16 = 4 * 4 == sqrt(a) * sqrt(a) == a
- 2) x != y, x < y, x < sqrt(a), y > sqrt(a)
- 28, sqrt(28) = 6
- 1, 2, 4, 7, 14, 28
- a == 10^9
- O(a) ~ 10^10 ~ TL
- O(sqrt(a)) ~ 10^5 ~ AC
- */
- // 2, 3, 5, 7, 11, 13, 17, 19
- // 18 = 2 * 3 * 3
- // 9
- // 3
- // 1
- int main()
- {
- int a;
- cin >> a;
- // Вывод всех делителей за линию.
- for (int i = 0; i < a; ++i) { // O(a)
- if (a % i == 0) {
- cout << i << " ";
- }
- }
- // Вывод всех делителей за корень.
- for (int i = 0; i * i <= a; ++i) { // O(sqrt(a))
- if (a % i == 0) {
- cout << i << " ";
- if (a / i != i) {
- cout << a / i << " ";
- }
- }
- }
- // Проверка на простоту.
- int cnt = 0;
- for (int i = 0; i * i <= a; ++i) { // O(sqrt(a))
- if (a % i == 0) {
- ++cnt;
- if (a / i != i) {
- ++cnt;
- }
- }
- }
- if (cnt == 2) {
- cout << "YES\n";
- } else {
- cout << "NO\n";
- }
- // Проверка на простоту.
- bool flag = true;
- for (int i = 2; i * i <= a; ++i) { // O(sqrt(a))
- if (a % i == 0) {
- cout << "NO";
- flag = false;
- break;
- }
- }
- if (flag) {
- cout << "YES";
- }
- // Факторизация числа за O(sqrt(a))
- for (int i = 2; i * i <= a; ++i) {
- while (a % i == 0) {
- cout << i << ' ';
- a /= i;
- }
- }
- if (a != 1) {
- cout << a;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement