Advertisement
Josif_tepe

Untitled

Mar 21st, 2024
442
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 0
  1. #include <iostream>
  2.      
  3. using namespace std;
  4.  
  5. int main() {
  6.     ios_base::sync_with_stdio(false);
  7.     int n;
  8.     cin >> n;
  9.     int niza[n];
  10.      
  11.     for(int i = 0; i < n; i++) {
  12.         cin >> niza[i];
  13.     }
  14.     int max_cnt =0 ;
  15.     int broj = 0;
  16.     for(int i = 0; i < n; i++) {
  17.         int cnt =0 ;
  18.         for(int a = 1; a <= niza[i]; a++) {
  19.             for(int k = 0; k <= niza[i]; k++) {
  20.                 int d = (k + 1) * a + ((k * (k + 1)) / 2);
  21.                
  22.                 if(d == niza[i]) {
  23.                     cnt++;
  24.                 }
  25.             }
  26.         }
  27.         if(max_cnt < cnt) {
  28.             max_cnt = cnt;
  29.             broj = niza[i];
  30.         }
  31.         else if(max_cnt == cnt) {
  32.             if(broj > niza[i]) {
  33.                 broj = niza[i];
  34.             }
  35.         }
  36.     }
  37.     cout << broj << " " << max_cnt << endl;
  38.     return 0;
  39. }
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement