Pagini recente » Cod sursa (job #897372) | Cod sursa (job #560835) | Cod sursa (job #3265484) | Cod sursa (job #2117049) | Cod sursa (job #585737)
Cod sursa(job #585737)
#include <algorithm>
#include <vector>
#include <cstdio>
#include <bitset>
#include <cmath>
using namespace std;
#define MAX 10000005
#define DIM 4005
#define LIM 10
double bst_0[DIM],bst_1[DIM],lg2[LIM+5];
int ant_0[DIM],ant_1[DIM];
bitset <MAX> viz;
int oldN,N,M,P;
void read ()
{
int i,j,bst_ant,bst_cur;
scanf ("%d",&N);
for (i=1; i<LIM; ++i)
lg2[i]=log (i);
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;
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<LIM && i-j>=1; ++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 (j<LIM && i-j==0)
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;
}