Sunday, September 28, 2014

UVa - 294 - Divisors

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;

int main(){
    int t, l, u, ans, mx, cnt;
    cin >> t;
    while(t--){
        cin >> l >> u;
        mx = -1;
        for(int i = l; i <= u; i++){
            cnt = 0;
            for(int j = 1; j <= sqrt(i); j++){
                if(i%j == 0){
                    cnt++;
                    if(i/j != j)cnt++;
                }
            }
            if(cnt > mx){
                mx = cnt;
                ans = i;
            }
        }
        cout << "Between " << l << " and " << u << ", " << ans << " has a maximum of " << mx << " divisors." << endl;
    }
    return 0;
}

No comments:

Post a Comment