Pagini recente » Cod sursa (job #816414) | Cod sursa (job #1353772) | sim.k | Cod sursa (job #2330673) | Cod sursa (job #402825)
Cod sursa(job #402825)
#include<stdio.h>
#include<math.h>
long int functie(long int n,long int p)
{
long int s=0;
while(n)
{
s=s+n/p;
n=n/p;
}
return s;
}
long int patru(long int n)
{
long int s=0;
long int i;
for(i=1;i<=n;i++)
{
long int t=i;
while(t%2==0)
{
s++;
t=t/2;
}
}
return s;
}
int main()
{
freopen("pascal.in","r",stdin);
freopen("pascal.out","w",stdout);
long int r,j,n,k1=0,k2=0,k3=0,d,p,c=0,i,q,s,t;
scanf("%ld%ld",&r,&d);
long k13, k12;
if(d==2||d==3||d==5)
{
k1=functie(r,d);
}else
{
if(d==4)
{
k1=patru(r);
}else
{
if(d==6)
{
k12=functie(r,2);
k13=functie(r, 3);
}
}
}
for(j=0;j<=r;j++)
{
p=r-j;
if(d==2||d==3||d==5)
{
k2=functie(p,d);
k3=functie(j,d);
if(k1-k2-k3>0)
{
c++;
}
}
else
{
if(d==4)
{
k2=patru(p);
k3=patru(j);
if(k1-k2-k3>0&&(k1-k2-k3)%2==0)
{
c++;
}
}
else
{
long k22=functie(p, 2);
long k23=functie(p, 3);
long k32=functie(j, 2);
long k33=functie(j, 3);
if(k12-k22-k32>0 && k13-k23-k33>0)
{
c++;
}
}
}
k2=0;
k3=0;
}
printf("%ld",c);
return 0;
}