Cod sursa(job #2341596)

Utilizator Cezar211Popoveniuc Cezar Cezar211 Data 11 februarie 2019 23:16:48
Problema Pascal Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.89 kb
#include <bits/stdc++.h>
#define NM 5000005
using namespace std;
ifstream fin ("pascal.in");
ofstream fout ("pascal.out");
typedef unsigned long long ull;
ull putere(ull a, ull b)///a^b
{
    ull p = 1;
    while(b)
    {
        if(b%2==1)
            p*=a;
        a*=a;
        b/=2;
    }
    return p;
}
int n, d, nr, fact[NM], ind[10];
void read();
int main()
{
    read();
    if(n == 0)
    {
        fout << 0;
        return 0;
    }
    for(int j=1; j<=n; j++)
    {
        ull a = fact[n-j]*fact[j];
        ///a^ind[d]
        a = putere(a, ind[d]-1);
        a*=fact[j];
        if(a%d == 0)
            nr++;
    }
    fout << nr;
    return 0;
}
void read()
{
    fin >> n >> d;
    fact[0] = 1;
    for(int i=1; i<=n; i++)
        fact[i] = (fact[i-1]*i)%d;
    ind[0] = ind[1] = ind[2] = 1;
    ind[3] = ind[4] = ind[6] = 2;
    ind[5] = 4;
}