Cod sursa(job #708076)

Utilizator gyeresihunorGyeresi Hunor gyeresihunor Data 6 martie 2012 13:22:50
Problema Pascal Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.87 kb
#include "stdio.h"

long long k;
long long d;
long long i;
long long m=1;
long long nr=0;
long long t[11];

void ad(long long x);
void vesz(long long x);

int main()
{
	freopen("pascal.in","r",stdin);
	freopen("pascal.out","w",stdout);
	scanf("%lld%lld",&k,&d);
	for(i=1;i<k;i++)
	{
		ad(k-i+1);
		vesz(i);
		switch(d)
		{
			case 2: if(t[2])nr++;break;
			case 3: if(t[3])nr++;break;
			case 4: if(t[2]%2==0)nr++;break;
			case 5: if(t[5])nr++;break;
			case 6: if(t[2]&&t[3])nr++;break;
			default: break;
		}
	}
	printf("%lld\n",nr);
	return 0;
}

void ad(long long x)
{
	while(x%2)
	{
		t[2]++;
		x/=2;
	}
	while(x%3)
	{
		t[3]++;
		x/=3;
	}
	while(x%5)
	{
		t[5]++;
		x/=5;
	}
}

void vesz(long long x)
{
	while(x%2)
	{
		t[2]--;
		x/=2;
	}
	while(x%3)
	{
		t[3]--;
		x/=3;
	}
	while(x%5)
	{
		t[5]--;
		x/=5;
	}
}