Pagini recente » Cod sursa (job #2834091) | Cod sursa (job #8708) | Cod sursa (job #1305195) | Cod sursa (job #806890) | Cod sursa (job #585914)
Cod sursa(job #585914)
#include <cstdio>
#define lmax 1000
int n, d, v[4000][lmax], h, f, a[10000], prev[4000], g[lmax];
char p[11000];
void produs(int a[lmax], int b[lmax], int x)
{
int i, t=0;
for (i=1; i<=a[0]; i++) a[i]=0;
a[0]=0;
for (i=1; i<=b[0]; i++)
{
a[0]++;
a[i]=b[i]*x+t;
t=a[i]/10;
a[i]%=10;
}
while (t)
{
a[++a[0]]=t%10;
t/=10;
}
}
int maimare(int a[lmax], int b[lmax])
{
if (a[0]>b[0]) return 1;
if (a[0]<b[0]) return 0;
int i;
for (i=a[0]; i>0; i--)
if (a[i]!=b[i]) return a[i]>b[i];
return 0;
}
int main()
{
freopen("nummst.in","r",stdin);
freopen("nummst.out","w",stdout);
scanf("%d",&n);
int i, c, k, s, x, j, y;
for (i=2; i*i<=n; i++)
{
if (!(n%i))
{
d=i;
break;
}
}
s=d;
d=n/d;
for (x=2; x<=s; x++)
for (i=x+x; i<=s; i+=x) p[i]=1;
for (i=1; i<=s; i++)
if (!p[i]) a[++f]=i;
// for (i=1; i<=f; i++) printf("%d\n",a[i]);
long long u;;
if (s==2)
{
h=2;
printf("%d %d\n",d,d);
} else
{
v[0][0]=1;
v[0][1]=1;
for (i=1; i<=f; i++)
for (j=s; j>=a[i]; j--)
if (v[j-a[i]][0])
{
produs(g, v[j-a[i]], a[i]);
// printf("\n");
// for (y=v[j-a[i]][0]; y>0; y--) printf("%d",v[j-a[i]][y]);
if (maimare(g, v[j]))
{
prev[j]=i;
for (y=0; y<=g[0]; y++) v[j][y]=g[y];
}
// printf("\n%d %d %d\n",i,j,a[i]);
// for (y=g[0]; y>0; y--)printf("%d",g[y]);
}
i=s;
while (i)
{
printf("%d ",a[prev[i]]*d);
i-=a[prev[i]];
}
}
// for (i=1; i<=h; i++) printf("%d ", v[i]*d);
return 0;
}