Cod sursa(job #1337673)

Utilizator ASTELOTudor Enescu ASTELO Data 9 februarie 2015 12:41:37
Problema Pascal Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.24 kb
#include<cstdio>
int r,i,j,rand,k,l,re,q,cq,cl,nr,put,pp;
int main ()
{
freopen("pascal.in","r",stdin);
freopen("pascal.out","w",stdout);
scanf("%d%d",&rand,&k);
if(k!=6)
    {
    if(k==4)
        {
        k=2;
        pp=1;
        }
    l=rand+1;
    for(i=2;i<=rand+1;i++)
        {
        l--;
        q++;
        cl=l;
        cq=q;
        while(cl%k==0)
            {
            put++;
            cl/=k;
            }
        while(cq%k==0)
            {
            put--;
            cq/=k;
            }
        if(put>0&&pp==0||pp==1&&put>1)
            nr++;
        }
    printf("%d",nr);
    }
else
    {
    l=rand+1;
    int put1=0;
    for(i=2;i<=rand+1;i++)
        {
        l--;
        q++;
        cl=l;
        cq=q;
        while(cl%2==0)
            {
            put++;
            cl/=k;
            }
        while(cq%2==0)
            {
            put--;
            cq/=k;
            }
        while(cl%3==0)
            {
            put1++;
            cl/=k;
            }
        while(cq%3==0)
            {
            put1--;
            cq/=k;
            }
        if(put>0&&put1>0)
            nr++;
        }
    printf("%d",nr);
    }
return 0;
}