Cod sursa(job #1672403)

Utilizator mateibanuBanu Matei Costin mateibanu Data 2 aprilie 2016 18:14:38
Problema Pascal Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.16 kb
#include <stdio.h>

using namespace std;

FILE*f=fopen("pascal.in","r");
FILE*g=fopen("pascal.out","w");

int ptr(long long d,long long l)
{
    long long p=d;
    long long nr=0;
    while (p<=l)
    {
        nr+=l/p;
        p*=d;
    }
    return nr;
}

int pt(long long d,long long l)
{
    long long nr=0;
    while (l%d==0)
    {
        l/=d;
        nr++;
    }
    return nr;
}

int fac[5000030];

int main()
{
    long long r,p,d,d1,ok=0,nr,nr1,i,x,s=0;
    fscanf(f,"%lld%lld",&r,&d);
    fac[0]=0;
    if (d==4)
    {
        for (i=1;i<=r;i++) fac[i]=fac[i-1]+pt(2,i);
        for (i=1;i<r/2;i++) if (fac[r]-fac[i]-fac[r-i]>=2) s++;
        s*=2;
        if ((r+1)%2)
        {
            i=(r+1)/2+(r+1)%2;
            if (fac[r]-fac[i]-fac[r-i]>=2) s++;
        }
    }
    else
    {
        for (i=1;i<=r;i++) fac[i]=fac[i-1]+pt(d,i);
        for (i=1;i<r/2;i++) if (fac[r]-fac[i]-fac[r-i]>0) s++;
        s*=2;
        if ((r+1)%2)
        {
            i=(r+1)/2+(r+1)%2;
            if (fac[r]-fac[i]-fac[r-i]>0) s++;
        }
    }
    fprintf(g,"%lld",s);
    fclose(g);
    fclose(f);
    return 0;
}