Cod sursa(job #1167358)

Utilizator gerd13David Gergely gerd13 Data 4 aprilie 2014 20:48:11
Problema Pascal Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.23 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 k, int h)
{
  Solving(k - h + 1, 1) ;
        Solving(h, -1) ;
}


int main()
{
    cin >> R >> D ;
    //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 ;
    cin.close() ;
    cout.close() ;
    return 0;
}