Cod sursa(job #3225988)

Utilizator BuzdiBuzdugan Rares Andrei Buzdi Data 19 aprilie 2024 15:28:52
Problema Pascal Scor 50
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.5 kb
#include <fstream>
#include <stack>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#define ll long long

using namespace std;

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

const int primes[7][4] ={{0, 0, 0, 0},
                         {0, 0, 0, 0},
                         {2, 2, 1, 0},
                         {2, 3, 1, 0},
                         {2, 2, 2, 0},
                         {2, 1, 5, 0},
                         {3, 2, 3, 1}};

int n, D, answer, good_middle;
int expF[3];

int Legendre(int p, int n)
{
    int curent_p = p, cnt_p = 0;
    while(curent_p <= n)
    {
        cnt_p += n / curent_p;
        curent_p *= p;
    }
    return cnt_p;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> n >> D;

    for(int i = 1; i <= primes[D][0] - 1; i++)
        expF[i] = Legendre(primes[D][i], n);

    for(int i = 0; i <= n / 2; i++)
    {
        int good = 1;
        for(int j = 1; j <= primes[D][0] - 1 && good == 1; j++)
        {
            int curent_exp1 = Legendre(primes[D][j], i);
            int curent_exp2 = Legendre(primes[D][j], n - i);

            int exactly_exp = expF[j] - curent_exp1 - curent_exp2;
            if(exactly_exp < primes[D][primes[D][0]])
                good = 0;
            else if(n % 2 == 0 && i == n / 2)
                good_middle = 1;
        }
        answer += good;
    }

    cout << answer * 2 - good_middle;


    return 0;
}