Advertisement
MathQ_

Untitled

Jan 10th, 2021
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. #include <set>
  4. #include <map>
  5.  
  6. using namespace std;
  7.  
  8. void fact(int n, map<int, int> &facts) {
  9.     for (int i = 2; i * i <= n; ++i) {
  10.         while (n % i == 0) {
  11.             facts[i]++;
  12.             n /= i;
  13.         }
  14.     }
  15. }
  16.  
  17. int main() {
  18.     int n;
  19.     cin >> n;
  20.     set<pair<int, int>> q;
  21.     for (int i = 1; i <= n; ++i) {
  22.         map<int, int> facts;
  23.         fact(i, facts);
  24.         int res = 1;
  25.         for (auto [p, e] : facts) {
  26.             if (p % 4 == 1) {
  27.                 res *= 2 * e + 1;
  28.             }
  29.         }
  30.         if (q.empty() || res * 4 > (*q.rbegin()).fi) {
  31.             q.insert({res * 4, i});
  32.         }
  33.     }
  34.     for (auto el : q) {
  35.         cout << el.fi << " " << el.se << '\n';
  36.     }
  37.  
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement