Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #define int long long
- using namespace std;
- void print_div(int n) {
- for (int a = 1; a * a <= n; a++)
- if (n % a == 0) {
- cout << a << ' ' << n / a << ' ';
- }
- }
- ///primality test
- bool is_prime(int n) {
- if (n == 1)
- return 0;
- for (int a = 2; a * a <= n; a++)
- if (n % a == 0) {
- return 0;
- }
- return 1;
- }
- void factorization(int n) {
- int initialN = n;
- for (int p = 2; p * p <= initialN; p++)
- if (n % p == 0) {
- ///try to use it
- int cnt = 0;
- while (n % p == 0) {
- n = n / p;
- cnt++;
- }
- cout << "Number " << p << " appears " << cnt << " times.\n";
- }
- ///n from which we removed all primes <= sqrt(initial n)
- ///n = 1 -- no prime numbers left
- ///n > 1 ---> n = p[i] which is large, > sqrt(initial n)
- if (n > 1)
- cout << "Number " << n << " appears " << 1 << " times.\n";
- }
- signed main()
- {
- int n;
- cin >> n;
- factorization(n);
- //cout << is_prime(n);
- //print_div(n);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement