Pagini recente » Cod sursa (job #1664272) | Cod sursa (job #605493) | Cod sursa (job #2351998) | Cod sursa (job #15251) | Cod sursa (job #957542)
Cod sursa(job #957542)
#include <cstdio>
using namespace std;
int r,d,up,down,x,cnt,Cnt,sol;
int main()
{
freopen("pascal.in","r",stdin);
freopen("pascal.out","w",stdout);
scanf("%d%d",&r,&d);
up=r;down=1;
if(d<6)
{
//caz 2,3,5
for(;up>down+1;up--,down++)
{
x=up;
while(x%d==0){cnt++;x/=d;}
x=down;
while(x%d==0){cnt--;x/=d;}
if(cnt)sol+=2;
}
if(up==down+1)
{
x=up;
while(x%d==0){cnt++;x/=d;}
x=down;
while(x%d==0){cnt--;x/=d;}
if(cnt)sol++;
}
printf("%d\n",sol);
return 0;
}
for(;up>down+1;up--,down++)
{
x=up;
while(x%2==0){Cnt++;x/=d;}
while(x%3==0){cnt++;x/=d;}
x=down;
while(x%2==0){Cnt++;x/=d;}
while(x%3==0){cnt++;x/=d;}
if(cnt&&Cnt)sol+=2;
}
if(up==down+1)
x=up;
while(x%2==0){Cnt++;x/=d;}
while(x%3==0){cnt++;x/=d;}
x=down;
while(x%2==0){Cnt++;x/=d;}
while(x%3==0){cnt++;x/=d;}
if(cnt&&Cnt)sol++;
printf("%d\n",sol);
return 0;
}