Cod sursa(job #808550)

Utilizator danalex97Dan H Alexandru danalex97 Data 6 noiembrie 2012 21:48:33
Problema Pascal Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.77 kb
#include <fstream>
using namespace std;

ifstream F("pascal.in");
ofstream G("pascal.out");

int D,R,P[7],Sol,M;

#define INC Sol += 1+(2*i!=R);

int main ()
{
    F>>R>>D;

    int Stop = R/2;
    for (int i=1;i<=Stop;++i)
    {
        M=R-i+1;
        while ( M%2 == 0 ) P[2]++,M/=2;
        while ( M%3 == 0 ) P[3]++,M/=3;
        while ( M%5 == 0 ) P[5]++,M/=5;
        M=i;
        while ( M%2 == 0 ) P[2]--,M/=2;
        while ( M%3 == 0 ) P[3]--,M/=3;
        while ( M%5 == 0 ) P[5]--,M/=5;

        P[6]=min(P[2],P[3]);

        if ( D == 2 && P[2] > 0 ) INC;
        if ( D == 3 && P[3] > 0 ) INC;
        if ( D == 4 && P[2] > 1 ) INC;
        if ( D == 5 && P[5] > 0 ) INC;
        if ( D == 6 && P[6] > 0 ) INC;
    }

    G<<Sol<<'\n';
}