fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. void executeTime() {
  5. cerr << "Time Taken: " << (float)clock() / CLOCKS_PER_SEC << " secs";
  6. }
  7.  
  8. int main() {
  9.  
  10. int n; cin >> n;
  11.  
  12. vector<int> spf(n + 1, 1);
  13.  
  14. spf[0] = 0;
  15. for (int i = 0; i <= n; i++) {
  16. spf[i] = i;
  17. }
  18.  
  19.  
  20. for (int i = 2; i <= sqrt(n); i++) {
  21. for (int j = i * i; j <= n; j += i) {
  22. if (spf[j] == j) spf[j] = i;
  23. }
  24. }
  25.  
  26. vector<int> v(4);
  27.  
  28. auto print_prime_factorisation = [&](int n) {
  29. map<int, int> mp;
  30.  
  31. while (n > 1) {
  32. mp[spf[n]] ++;
  33. n /= spf[n];
  34. }
  35.  
  36. for (auto &x : mp) {
  37. cout << x.first << ' ' << x.second << endl;
  38. }
  39.  
  40. cout << endl;
  41. };
  42.  
  43. for (auto &x : v) {
  44. cin >> x;
  45. print_prime_factorisation(x);
  46. }
  47.  
  48.  
  49.  
  50.  
  51. executeTime();
  52. return 0;
  53. }
Success #stdin #stdout #stderr 0.01s 5284KB
stdin
40
40 10 20 5
stdout
2 3
5 1

2 1
5 1

2 2
5 1

5 1

stderr
Time Taken: 0.004886 secs