Cod sursa(job #2769119)

Utilizator Y.MalmsteenB.P.M. Y.Malmsteen Data 13 august 2021 15:44:54
Problema Pascal Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.17 kb
#include <fstream>

using namespace std;

ifstream f("pascal.in");
ofstream g("pascal.out");

int expp(int n, int p)
{
    int e = 0;
    while(n % p == 0)
    {
        e++;
        n /= p;
    }
    return e;
}

int main()
{
    int R, D, nrd = 0;
    f >> R >> D;
    //
    if(R >= 2)
    {
        int ex2 = 0, ex3 = 0, ex5 = 0,
            ed2 = 0, ed3 = 0, ed5 = 0,
            r2 = (R + 1) / 2;
        while(D % 2 == 0) D /= 2, ex2++;
        while(D % 3 == 0) D /= 3, ex3++;
        while(D % 5 == 0) D /= 5, ex5++;
        //
        for(int k = 1; k < r2; k++)
        {
            ed2 += expp(R - k + 1, 2) - expp(k, 2);
            ed3 += expp(R - k + 1, 3) - expp(k, 3);
            ed5 += expp(R - k + 1, 5) - expp(k, 5);
            nrd += ed2 >= ex2 && ed3 >= ex3 && ed5 >= ex5;
        }
        nrd *= 2;
        if(R % 2 == 0)
        {
            ed2 += expp(r2 + 1, 2) - expp(r2, 2);
            ed3 += expp(r2 + 1, 3) - expp(r2, 3);
            ed5 += expp(r2 + 1, 5) - expp(r2, 5);
            nrd += ed2 >= ex2 && ed3 >= ex3 && ed5 >= ex5;
        }
    }
    g << nrd;
    f.close();
    g.close();
    return 0;
}