Cod sursa(job #2326950)

Utilizator mihaicosmin2011Mihai Cosmin mihaicosmin2011 Data 24 ianuarie 2019 11:58:49
Problema Numarare triunghiuri Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.83 kb
#include <fstream>
using namespace std;
int nrdiv(int n)
{
    int nrd = 1, fm = 0, d = 2;
    while(n % d == 0)
    {
        fm ++;
        n = n / d;
    }
    nrd *= (fm + 1);
    d ++;
    while(n != 1 && d * d <= n)
    {
        fm = 0;
        while(n % d == 0)
        {
            fm ++;
            n = n / d;
        }
        nrd = nrd * (fm + 1);
        d = d + 2;
    }
    if(n != 1) nrd = nrd * 2;
    return nrd;
}
int a, b, i, x, maxx, c, ct;
int main()
{
    ifstream f("maxd.in");
    ofstream g("maxd.out");
    f >> a >> b;
    for(i = a; i <= b; i ++)
    {
        x = nrdiv(i);
        if(x > maxx)
        {
            maxx = x;
            c = i;
            ct = 1;
        }
        else if(x == maxx) ct ++;
    }
    g << c << " " << maxx << " " << ct;
    return 0;
}