Pagini recente » Cod sursa (job #2331357) | Cod sursa (job #1132268) | Cod sursa (job #417607) | Cod sursa (job #2678805) | Cod sursa (job #585741)
Cod sursa(job #585741)
#include <algorithm>
#include <vector>
#include <cstdio>
#include <bitset>
#include <cmath>
using namespace std;
#define MAX 10000005
#define DIM 4005
double bst_0[DIM],bst_1[DIM],lg2[DIM];
int ant_0[DIM],ant_1[DIM];
bitset <MAX> viz;
int oldN,N,M,P;
void read ()
{
int i,j;
scanf ("%d",&N);
oldN=N;
if (!(N&1))
N=2;
for (i=3; i<=N; i+=2)
if (!viz[i])
{
if (!(N%i))
{
N=i;
return ;
}
for (j=3*i; j<=N; j+=(i<<1))
viz[j]=1;
}
}
void solve ()
{
int i,j,val;
for (i=1; i<=N; ++i)
lg2[i]=log (i);
bst_0[1]=0; ant_0[1]=1;
bst_1[1]=0; ant_1[1]=1;
for (i=2; i<=N; ++i)
{
bst_1[i]=bst_1[i-1]; ant_1[i]=1;
for (j=1; j<i; ++j)
if (bst_0[i-j]+lg2[j]>bst_1[i])
{
bst_1[i]=bst_0[i-j]+lg2[j];
ant_1[i]=j;
}
bst_0[i]=bst_1[i]; ant_0[i]=ant_1[i];
if (lg2[i]>bst_0[i])
{
bst_0[i]=lg2[i];
ant_0[i]=i;
}
}
printf ("%d ",ant_1[N]*(oldN/N));
for (val=N-ant_1[N]; val; val-=ant_0[val])
printf ("%d ",ant_0[val]*(oldN/N));
}
int main ()
{
freopen ("nummst.in","r",stdin);
freopen ("nummst.out","w",stdout);
read ();
solve ();
return 0;
}