Cod sursa(job #1887708)

Utilizator ReeeBontea Mihai Reee Data 21 februarie 2017 18:48:34
Problema Pascal Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.76 kb
#include <fstream>

using namespace std;

int R , D; // cate de pe linia R sunt divizibile la D

unsigned int f( unsigned int x )
{
    unsigned int p = 1;
    for ( unsigned int i = 1 ; i <= x ; ++i )
        p *= i;
    return p;
}


int main()
{
    ifstream fin("pascal.in");
    ofstream fout("pascal.out");

    fin >> R >> D;
    unsigned int k = 0;

    //i!/((i-j)!*j!)

    for ( unsigned int j = 0 ; j < R / 2 ; ++j )
    {
        if ( ( f( R ) / ( f( R - j ) * f ( j ) ) ) % D == 0 )
            ++k;
    }

    k *= 2;

    if ( ( R + 1 ) % 2 != 0 ) // caz particular , nr impar
        if ( ( f( R ) / ( f( R - ( ( R + 1 ) / 2 + 1 ) ) * f ( ( R + 1 ) / 2 + 1 ) ) ) % D == 0 )
            ++k;

    fout << k;

    return 0;
}