Cod sursa(job #2561291)

Utilizator Octav02Cosofret Octavian-Stefan Octav02 Data 28 februarie 2020 18:32:00
Problema Suma si numarul divizorilor Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.81 kb
#include <fstream>

using namespace std;
ifstream fin("maxd.in");
ofstream fout("maxd.out");

int nrdiv (int n) {
    int div = 1, d = 2, p = 0;
    while(n > 1) {
        p = 0;
        while(n % d == 0) {
            ++p;
            n /= d;
        }
        if(p)
            div *= p + 1;
        ++d;
        if (n > 1 && d * d > n){
            d = n;
        }
    }
    return div;
}
int a, b, maxim, minim, counter;
int main() {
    fin >> a >> b;
    for (int i = b; i >= a; i -= 2) {
        if (maxim < nrdiv(i)) {
            minim = i;
            maxim = nrdiv(i);
            counter = 0;
        }
        if (maxim == nrdiv(i))
            counter++;
        if (i % 2 != 0)
            i++;
    }
    fout << minim << ' ' << maxim << ' ' << counter;
    return 0;
}