fork download
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <map>
  4.  
  5. using namespace std;
  6.  
  7. map<unsigned int, unsigned int> factorize(unsigned int n)
  8. {
  9. map<unsigned int, unsigned int> m;
  10. while(n > 1 && n%2 == 0)
  11. {
  12. m[2]++;
  13. n /= 2;
  14. }
  15. if (n > 1) for(unsigned int i = 3; i <= n;)
  16. {
  17. if (n%i == 0) { m[i]++; n /= i; continue; }
  18. i += 2;
  19. }
  20. return m;
  21. }
  22.  
  23. int main(int argc, const char * argv[])
  24. {
  25. for(unsigned int i = 1; i <= 100; ++i)
  26. {
  27. auto m = factorize(i);
  28. cout << i << ": ";
  29. for(auto it = m.begin(); it != m.end(); ++it)
  30. {
  31. cout << it->first << "^" << it->second << " ";
  32. }
  33. cout << endl;
  34. }
  35. }
  36.  
  37.  
Success #stdin #stdout 0s 4516KB
stdin
Standard input is empty
stdout
1: 
2: 2^1  
3: 3^1  
4: 2^2  
5: 5^1  
6: 2^1  3^1  
7: 7^1  
8: 2^3  
9: 3^2  
10: 2^1  5^1  
11: 11^1  
12: 2^2  3^1  
13: 13^1  
14: 2^1  7^1  
15: 3^1  5^1  
16: 2^4  
17: 17^1  
18: 2^1  3^2  
19: 19^1  
20: 2^2  5^1  
21: 3^1  7^1  
22: 2^1  11^1  
23: 23^1  
24: 2^3  3^1  
25: 5^2  
26: 2^1  13^1  
27: 3^3  
28: 2^2  7^1  
29: 29^1  
30: 2^1  3^1  5^1  
31: 31^1  
32: 2^5  
33: 3^1  11^1  
34: 2^1  17^1  
35: 5^1  7^1  
36: 2^2  3^2  
37: 37^1  
38: 2^1  19^1  
39: 3^1  13^1  
40: 2^3  5^1  
41: 41^1  
42: 2^1  3^1  7^1  
43: 43^1  
44: 2^2  11^1  
45: 3^2  5^1  
46: 2^1  23^1  
47: 47^1  
48: 2^4  3^1  
49: 7^2  
50: 2^1  5^2  
51: 3^1  17^1  
52: 2^2  13^1  
53: 53^1  
54: 2^1  3^3  
55: 5^1  11^1  
56: 2^3  7^1  
57: 3^1  19^1  
58: 2^1  29^1  
59: 59^1  
60: 2^2  3^1  5^1  
61: 61^1  
62: 2^1  31^1  
63: 3^2  7^1  
64: 2^6  
65: 5^1  13^1  
66: 2^1  3^1  11^1  
67: 67^1  
68: 2^2  17^1  
69: 3^1  23^1  
70: 2^1  5^1  7^1  
71: 71^1  
72: 2^3  3^2  
73: 73^1  
74: 2^1  37^1  
75: 3^1  5^2  
76: 2^2  19^1  
77: 7^1  11^1  
78: 2^1  3^1  13^1  
79: 79^1  
80: 2^4  5^1  
81: 3^4  
82: 2^1  41^1  
83: 83^1  
84: 2^2  3^1  7^1  
85: 5^1  17^1  
86: 2^1  43^1  
87: 3^1  29^1  
88: 2^3  11^1  
89: 89^1  
90: 2^1  3^2  5^1  
91: 7^1  13^1  
92: 2^2  23^1  
93: 3^1  31^1  
94: 2^1  47^1  
95: 5^1  19^1  
96: 2^5  3^1  
97: 97^1  
98: 2^1  7^2  
99: 3^2  11^1  
100: 2^2  5^2