Pagini recente » Cod sursa (job #3189356) | Cod sursa (job #2983838) | Cod sursa (job #1235080) | Cod sursa (job #2454555) | Cod sursa (job #58698)
Cod sursa(job #58698)
#include<stdio.h>
int a, nr, d, r, i, p, p1, p2, P, P2, P1, x, y;
int main()
{
freopen("pascal.in","r",stdin);
freopen("pascal.out","w",stdout);
scanf("%d%d",&r,&d);
if (d==2||d==3||d==5){
a=d;
p=0;
while (a<=r){
p+=(r/a);
a*=d;
}
p1=p;
p2=0;
for (i=1;i<=r/2;i++){
x=0;
y=r-i+1;
while (y%d==0){
x++;
y/=d;
}
p1-=x;
x=0;
y=i;
while (y%d==0){
x++;
y/=d;
}
p2+=x;
if (p-p1-p2>0) nr++;
}
if (r%2==1) printf("%d\n",2*nr);
else printf("%d\n",2*nr-1);
return 0;
}
if (d==4){
a=2;
p=0;
while (a<=r){
p+=(r/a);
a*=2;
}
p1=p;
p2=0;
for (i=1;i<=r/2;i++){
x=0;
y=r-i+1;
while (y%2==0){
x++;
y/=2;
}
p1-=x;
x=0;
y=i;
while (y%2==0){
x++;
y/=2;
}
p2+=x;
if (p-p1-p2>1) nr++;
}
}
if (d==6){
printf("%d",d/0);
a=2;
p=0;
while (a<=r){
p+=(r/a);
a*=2;
}
p1=p;
p2=0;
a=3;
P=0;
while (a<=r){
P+=(r/a);
a*=3;
}
P1=P;
P2=0;
for (i=1;i<=r/2;i++){
x=0;
y=r-i+1;
while (y%2==0){
x++;
y/=2;
}
p1-=x;
x=0;
y=i;
while (y%2==0){
x++;
y/=2;
}
p2+=x;
x=0;
y=r-i+1;
while (y%3==0){
x++;
y/=d;
}
P1-=x;
x=0;
y=i;
while (y%3==0){
x++;
y/=d;
}
P2+=x;
if ((p-p1-p2>0)&&(P-P1-P2>0)) nr++;
}
if (r%2==1) printf("%d\n",2*nr);
else printf("%d\n",2*nr-1);
return 0;
}
}