Cod sursa(job #838716)

Utilizator cat_red20Vasile Ioana cat_red20 Data 20 decembrie 2012 13:11:13
Problema Descompuneri Scor 12
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.69 kb
#include<stdio.h>
#include<algorithm>
using namespace std;
int a[1000][1000],dvz[1000],d,n,k;

void citire()
{
    freopen("desc.in","r",stdin);
    scanf("%d %d",&n,&k);
}

void divizori()
{
    for(int i=1;i<=n/2;i++)
    {
        if(n%i==0)
        {
            dvz[d++]=i;
            if(n/i<=i)
            {
                break;
            }
            else
            dvz[d++]=n/i;
        }
    }
    sort(dvz,dvz+d);
    d--;
}

void din()
{
    int x;
    for(int i=1;i<=d;i++)
    {
        x=0;
        a[i][i]=1;
        a[0][i]=1;
        for(int j=i-1;j>=1;j--)
        {
            a[i][j]=a[i][j+1];
            while(dvz[x]*dvz[j]<dvz[i])
            x++;
            if(dvz[x]*dvz[j]==dvz[i])
            {
                a[i][j]+=a[x][j];
            }
        }
    }
}

int cauta(int x,int p,int u)
{
    int m;
    while(p<=u)
    {
        m=(p+u)/2;
        if(dvz[m]==x)
        return m;
        if(dvz[m]<x)
        p=m+1;
        else
        u=m-1;
    }
    return 0;
}

void afisare()
{
    int i,j,dvzp=1,u=d;
    freopen("desc.out","w",stdout);
    printf("%d\n",a[d][1]);
    /*while(k!=0 && j!=0)
    {

        for(i=dvzp;i<=u;i++)
        {
            if(dvz[u]%dvz[i]!=0)
            continue;
            j=cauta(dvz[u]/dvz[i],dvzp,u);
            if(a[j][i]<k)
            {
                k-=a[j][i];
            }
            else
            {
                printf("%d ",dvz[i]);
                dvzp=i;
                u=j;
                break;
            }
        }
    }*/
}

int main()
{
    citire();
    divizori();
    din();
    afisare();
    return 0;
}