Advertisement
Josif_tepe

Untitled

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