Pagini recente » Cod sursa (job #1642280) | Cod sursa (job #1478029) | Cod sursa (job #928643) | Cod sursa (job #1666536) | Cod sursa (job #561414)
Cod sursa(job #561414)
#include<iostream.h>
#include<fstream.h>
long long n,p,k,st[1000001],x,a[1000001];
int as,ev,e,y;
void init()
{
if(x==1) st[x]=1;
else st[x]=st[x-1]-1;
}
int succesor()
{
if(st[x]<n)
{
st[x]++;
return 1;
}
else {
p=p/st[x-1];
return 0;
}
}
int valid()
{
if(p*st[x]<=n)
{
p=p*st[x];
return 1;
}
else return 0;
}
int solutie()
{ return (p==n);}
void tipar()
{
int i=1;
while(i<x)
{
a[i]=st[i];
i++;
}
a[i]=st[x];
y=x;
}
int bt()
{
x=1;
init();
while(x>0)
{
as=1; ev=0;
while(as && !ev)
{
as=succesor();
if(as) ev=valid();
}
if(as)
if(solutie())
{ e++;
p=p/st[x];
if(e==k) tipar();
}
else { x++; init(); }
else x--;
}
return e;
}
int main()
{
ifstream f;
f.open("desc.in");
ofstream g;
g.open("desc.out");
g<<bt();
g<<endl;
for(int i=1;i<=y;i++)
g<<a[i]<<" ";
f.close();
g.close();
return 0;
}