Cod sursa(job #1167357)

Utilizator gerd13David Gergely gerd13 Data 4 aprilie 2014 20:39:16
Problema Pascal Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.26 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 = pfirst + P ;
        N = N / 2 ;
    }
    while(N % 3 != 0)
    {
        psecond =psecond +  P ;
        N = N / 3 ;
    }
    while(N % 5 != 0)
    {
        pfive =pfive +  P ;
        N = N / 5 ;
    }
}


void pentru_for_funny(int R, int i)
{
  Solving(R - i + 1, 1) ;
        Solving(i, -1) ;
}

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

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

    for(int i = 1 ; i < rnou; ++ i)
    {
        pentru_for_funny(R, i) ;
        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;
}