Cod sursa(job #73640)

Utilizator peanutzAndrei Homorodean peanutz Data 20 iulie 2007 00:51:39
Problema Descompuneri Scor 8
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.3 kb
#include <stdio.h>
#include <math.h>

#define NMAX 200

long long n;
int k;
long long d[NMAX], h;
int a[NMAX][NMAX];
int aux;

void findDiv()
{
	int i, until = n, h = -1;
	d[++h] = 1;
	if(!(n%2))
		d[++h] = 2;

	for(i = 3; i <= until; ++i)
		if(!(n%i))
			d[++h] = i;
	aux = h;
}

int binarySearch(long long x)
{
	int st = 0, dr = h, m;
	dr = aux;
	while(st <= dr)
	{
		m = (st+dr) >> 1;
		if(d[m] > x)
			dr = m-1;
		else if(d[m] < x)
			st = m+1;
		else
			return m;
	}
	return -1;
}

void buildNr()
{
	int i, j, res;
	for(j = 1; j <= h; ++j)
		++a[0][j];

	for(i = 1; i <= h; ++i)
	{
		for(j = h; j; --j)
		{
			a[i][j] = a[i][j+1];
			if(!(d[i]%d[j]))
			{
				res = binarySearch(d[i]/d[j]);
				if(res != -1)
					a[i][j] += a[res][j];

			}
		}
	}
}

int main()
{
	freopen("desc.in", "r", stdin);
	freopen("desc.out", "w", stdout);

	scanf("%lld%lld", &n, &k);

	findDiv();

	h = aux;

	buildNr();

	printf("%d\n", a[h][1]);

    /*
	int i, aux;
	while(n != 1 && n != 0)
	{
		for(i = 1; i <= h && n != 1; ++i)
		{
			if((n % d[i]))
				continue;
			aux = binarySearch(n/d[i]);

			if(a[ aux ][i] >= k)
			{
				printf("%d ", d[i]);
				n /= d[i];
				--i;
			}
			else
				k -= a[ aux ][i];
		}
	}

    */

	return 0;
}