Cod sursa(job #451078)

Utilizator crushackPopescu Silviu crushack Data 8 mai 2010 22:18:12
Problema Pascal Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.48 kb
#include <stdio.h>

int main()
{
	int n,d,i,j,k,nd,m,c;
	freopen("pascal.in","r",stdin);
	freopen("pascal.out","w",stdout);
	
	scanf("%d%d",&n,&d);
	nd=0;
	
	k=n;m=n/2;c=0;
	for (i=0;i<m;i++)
	{
		int ax=k;
		while (!(ax%d))
		{
			ax/=d;
			nd++;
		}
		
		ax=n-k+1;
		while (!(ax%d))
		{
			ax/=d;
			nd--;
		}
		
		if (nd)
			c++;
		k--;
	}
	if ( !(n%2) )
	{
		c= (nd) ?(c-1)*2 +1 : c*2;
	}
	else
	{
		c*=2;
	}
	printf("%d\n",c);
	return 0;
}