Advertisement
Josif_tepe

Untitled

Mar 24th, 2022
810
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. #include <iostream>
  2. #include <set>
  3. #include <algorithm>
  4. using namespace std;
  5. typedef long long ll;
  6. int main()
  7. {
  8.     int n;
  9.     cin >> n;
  10.     ll max_sum = 0, num = 2e9;
  11.     for(int i = 0; i < n; i++) {
  12.         ll x;
  13.         cin >> x;
  14.         ll cnt = 0;
  15.         for(ll k = 1; k * (k + 1) < 2 * x; k++) {
  16.             double a = ((double) x - (k * (k + 1)) / 2) / (k + 1);
  17.             if(a - (ll)a == 0.0) {
  18.                 cnt++;
  19.             }
  20.         }
  21.         if(max_sum < cnt) {
  22.             max_sum = cnt;
  23.             num = x;
  24.         }
  25.         else if(max_sum == cnt and num > x) {
  26.             num = x;
  27.         }
  28.     }
  29.     cout << num << " " << max_sum + 1 << endl;
  30.  
  31.     return 0;
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement