Cod sursa(job #217044)

Utilizator Mishu91Andrei Misarca Mishu91 Data 26 octombrie 2008 20:16:43
Problema Pascal Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.67 kb
#include <cstdio>

long N, Sol;
int D;

int log(int baza, long nr)
{
    int put = 0;

    while(1)
    {
        if(nr % baza)
            return put;
        nr /= baza;
        put++;
    }
}

void solve()
{
    int L = N >> 1;
    long Ant = 0, Act;
    for(int i = 1; i <= L; ++i)
    {
        Act = Ant + log(D, N - i + 1) - log(D, i);
        if(Act)
            ++Sol;
    }
    if(N & 1)
    {
        printf("%ld\n",2 * Sol);
        return;
    }
    if(Act)
        printf("%ld\n",2 * Sol - 1);
    else
        printf("%ld\n",2 * Sol);
}

int main()
{
    freopen("pascal.in","rt",stdin);
    freopen("pascal.out","wt",stdout);

    scanf("%ld %d",&N, &D);
    solve();
}