Cod sursa(job #3251026)

Utilizator Luca_georgescuLucageorgescu Luca_georgescu Data 24 octombrie 2024 16:48:53
Problema Pascal Scor 70
Compilator cpp-64 Status done
Runda cex_1 Marime 1.2 kb
#include <bits/stdc++.h>
#define ll long long

using namespace std;

ifstream f("pascal.in");
ofstream g("pascal.out");

int r,d,nr,c;
const int NMAX=5000005;
int div2,div3,div5;

struct
{
    int two,three,five;
}a[NMAX+5];

int calc_exp(int i, int p)
{
    int cnt=0;
    while ( i%p==0 )
    {
        cnt++;
        i/=p;
    }
    return cnt;
}

int main()
{
    ios_base::sync_with_stdio(false);
    f.tie(NULL);

    f >> r >> d;

    if ( d==2 )
        div2=1;
    if ( d==3 )
        div3=1;
    if ( d==4 )
        div2=2;
    if ( d==5 )
        div5=1;

    for (int i=1; i<=r; i++ )
    {
        a[i].two=calc_exp(i,2);
        a[i].three=calc_exp(i,3);
        a[i].five=calc_exp(i,5);
    }

    for (int i=1; i<=r; i++ )
    {
        a[i].two+=a[i-1].two;
        a[i].three+=a[i-1].three;
        a[i].five+=a[i-1].five;
    }

    for (int i=1; i<r; i++ )
    {
        int exp2=a[r].two-a[i].two-a[r-i].two; // r!/(r-i)!*i!
        int exp3=a[r].three-a[i].three-a[r-i].three;
        int exp5=a[r].five-a[i].five-a[r-i].five;
        if ( exp2>=div2 && exp3>=div3 && exp5>=div5 )
            nr++;
    }
    g << nr;
    return 0;
}