Untitled

mail@pastecode.io avatar
unknown
c_cpp
a month ago
844 B
1
Indexable
Never
#include <iostream>
     
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    long long niza[n];
     
    for(int i = 0; i < n; i++) {
        cin >> niza[i];
    }
    int max_cnt =0 ;
    int broj = 0;
    for(int i = 0; i < n; i++) {
        int cnt = 0;
        for(long long k = 1; k * (k + 1) < 2 * niza[i]; k++) {
            double tmp = (double) (niza[i] - k * (k + 1) / 2) / (double)(k + 1);
            
            if(tmp - (long long)tmp == 0.0) {
                cnt++;
            }
        }
        if(max_cnt < cnt) {
            max_cnt = cnt;
            broj = niza[i];
        }
        else if(max_cnt == cnt) {
            if(broj > niza[i]) {
                broj = niza[i];
            }
        }
    }
    cout << broj << " " << max_cnt + 1<< endl;
    return 0;
}
Leave a Comment