fork download
  1. #include <iostream>
  2. #include <map>
  3. using namespace std;
  4.  
  5. void primeFactorization(int test_case, int n) {
  6. map<int, int> factors;
  7.  
  8. // Phân tích n thành thừa số nguyên tố
  9. for (int i = 2; i * i <= n; i++) {
  10. while (n % i == 0) {
  11. factors[i]++;
  12. n /= i;
  13. }
  14. }
  15.  
  16. // Nếu n vẫn còn lớn hơn 1, thì nó là một số nguyên tố
  17. if (n > 1) {
  18. factors[n]++;
  19. }
  20.  
  21. // In kết quả
  22. cout << "Test " << test_case << ": ";
  23. for (auto it = factors.begin(); it != factors.end(); ++it) {
  24. cout << it->first << "(" << it->second << ") ";
  25. }
  26. cout << endl;
  27. }
  28.  
  29. int main() {
  30. int t;
  31. cin >> t;
  32.  
  33. for (int i = 1; i <= t; i++) {
  34. int n;
  35. cin >> n;
  36. primeFactorization(i, n);
  37. }
  38.  
  39. return 0;
  40. }
  41.  
Success #stdin #stdout 0s 5220KB
stdin
Standard input is empty
stdout
Standard output is empty