Cod sursa(job #1167344)

Utilizator gerd13David Gergely gerd13 Data 4 aprilie 2014 20:13:30
Problema Pascal Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.15 kb
#include <fstream>

using namespace std;

const int NMAX = 5000005 ;

ifstream cin("pascal.in") ;
ofstream cout("pascal.out") ;

int R, D, first, second, third, pfirst, psecond, pfive, rnou, sol;

void Solving(int N, int P)
{
    while(N % 2 == 0)
    {
        pfirst = P ;
        N = N / 2 ;
    }
    while(N % 3 == 0)
    {
        psecond = P ;
        N = N / 3 ;
    }
    while(N % 5 == 0)
    {
        pfive = P ;
        N = N / 5 ;
    }
}


inline void Pascal()
{
    while(!(D%2))
    {
        ++ first ;
        D = D / 2 ;
    }
    while(!(D%3))
    {
        ++ second ;
        D = D / 3 ;
    }
    while(!(D%5))
    {
        ++ third ;
        D = D / 5 ;
    }

    rnou = (R + 2) / 2  ; //jumate rand

    for(int i = 1 ; i < rnou; ++ i)
    {
        Solving(R - i + 1, 1) ;
        Solving(i, -1) ;
        sol = sol + (pfirst >= first) && (psecond >= second) && (pfive >= third) ;

    }
    sol <<=1;

    if(R % 2 == 0 && R)
    {
        -- sol;
    }

    cout << sol ;
}
int main()
{
    cin >> R >> D ;
    Pascal() ;
    cin.close() ;
    cout.close() ;
    return 0;
}