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. for (int i = 2; i <= n; i++) {
  27. cout << i << ' ' << spf[i] << endl;
  28. }
  29.  
  30.  
  31.  
  32. executeTime();
  33. return 0;
  34. }
Success #stdin #stdout #stderr 0.01s 5324KB
stdin
20
stdout
2 2
3 3
4 2
5 5
6 2
7 7
8 2
9 3
10 2
11 11
12 2
13 13
14 2
15 3
16 2
17 17
18 2
19 19
20 2
stderr
Time Taken: 0.006128 secs