Advertisement
Josif_tepe

Untitled

Mar 23rd, 2022
949
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. using namespace std;
  4. typedef long long ll;
  5. int main()
  6. {
  7.     ll n;
  8.     cin >> n;
  9.     ll najgolem_rez = 0, najmal_broj = 2e9;
  10.     for(int i = 0; i < n; i++) {
  11.         ll x;
  12.         cin >> x;
  13.         int cnt = 0;
  14.         for(ll k = 1; k * (k + 1) < 2 * x; k++) {
  15.             double a = ((double) x - (k * (k + 1)) / 2) / (k + 1);
  16.             if(a - (ll)a == 0.0) {
  17.                 cnt++;
  18.             }
  19.         }
  20.         if(najgolem_rez < cnt) {
  21.             najgolem_rez = cnt;
  22.             najmal_broj = x;
  23.         }
  24.         else if(najgolem_rez == cnt and najmal_broj > x) {
  25.             najmal_broj = x;
  26.         }
  27.     }
  28.  
  29.     cout << najmal_broj << " " << najgolem_rez + 1<< endl;
  30.     return 0;
  31. }
  32. // 1 2 3 0 5 6 7 0 1 2 3 0 9 9 9
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement