PTICH - Phân tích thừa số nguyên tố
Xem dạng PDF
Gửi bài giải
Điểm:
1,00 (OI)
Giới hạn thời gian:
0.5s
Giới hạn bộ nhớ:
256M
Tác giả:
Dạng bài
Ngôn ngữ cho phép
C, C#, C++, Go, Java, Pascal, Perl, PHP, PyPy, Python, Ruby, Rust, Scratch, Swift
Bạn lại được ra 1 nhiệm vụ dễ dàng : Cho số nguyên ~n~ phân tích ~n~ thành thừa số nguyên tố.
Input
Gồm duy nhất số nguyên dương ~n~ (~ 2 \le n \le 10^{18} ~).
Output
Gồm nhiều dòng mỗi dòng gồm 2 số nguyên dương. Số đầu tiên là thừa số nguyên tố ~p~, số thứ hai là số mũ của ~p~ trong phân tích thừa số nguyên tố của ~n~.
Chú ý cần sắp xếp các thừa số nguyên tố tăng dần theo thứ tự từ trên xuống.
Sample
Input #1
12
Output #1
2 2
3 1
Hint
Bài này cũng đơn giản thôi nhaa... Cố gắng AC nhá!!!!
Bình luận
include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// Nhân 2 số tránh tràn 64-bit ll mul_mod(ll a, ll b, ll mod) { ll res = 0; a %= mod; while (b) { if (b & 1) res = (res + a) % mod; a = (a * 2) % mod; b >>= 1; } return res; }
// Lũy thừa nhanh có modulo ll powmod(ll a, ll d, ll mod) { ll res = 1; a %= mod; while (d) { if (d & 1) res = mulmod(res, a, mod); a = mul_mod(a, a, mod); d >>= 1; } return res; }
// Miller–Rabin kiểm tra nguyên tố bool isPrime(ll n, int iter = 10) { if (n < 2) return false; if (n % 2 == 0) return n == 2; if (n % 3 == 0) return n == 3; if (n % 5 == 0) return n == 5;
}
// Pollard's Rho tìm 1 ước số ll rho(ll n) { if (n % 2 == 0) return 2; if (n % 3 == 0) return 3;
}
// Đệ quy phân tích thừa số map<ll, int> factors;
void factorize(ll n) { if (n == 1) return; if (isPrime(n)) { factors[n]++; return; } ll d = rho(n); factorize(d); factorize(n / d); }
int main() { srand(time(NULL)); ll n; cin >> n;
} code full ac cho ae nao can . bai nay kho vai pia , khong don gian dau