#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<cmath>
#include<cassert>
#include<cstring>
#include<iomanip>
using namespace std;
typedef long long i64;
#define out64 "%lld\n"
#define in64 "%lld"
/************ for topcoder by zz1215 *******************/
#define FOR(i,a,b) for( int i = (a) ; i <= (b) ; i ++)
#define FFF(i,a) for( int i = 0 ; i < (a) ; i ++)
#define FFD(i,a,b) for( int i = (a) ; i >= (b) ; i --)
#define S64(a) scanf(in64,&a)
#define SS(a) scanf("%d",&a)
#define LL(a) ((a)<<1)
#define RR(a) (((a)<<1)+1)
#define pb push_back
#define CL(Q) while(!Q.empty())Q.pop()
#define MM(name,what) memset(name,what,sizeof(name))
#define read freopen("in.txt","r",stdin)
#define write freopen("out.txt","w",stdout)
const int inf = 0x3f3f3f3f;
const i64 inf64 = 0x3f3f3f3f3f3f3f3fLL;
const double oo = 10e9;
const double eps = 10e-9;
const double pi = acos(-1.0);
int dp[111];
vector<int>p;
int pow(int a,int x)
{
int temp=1;
for(int i=1;i<=x;i++)
{
temp*=a;
}
return temp;
}
void dfs(int rest,int id=0,int sum=0,int now=1)
{
if(id>=int(p.size())) return ;
if(rest == 0)
{
if(sum<=100)
{
if(dp[sum]<now)
{
dp[sum]=now;
}
}
}
else
{
for(int i=0;pow(p[id],i)+sum<=100;i++)
{
if(i!=0)
{
dfs(rest-i,id+1,sum+pow(p[id],i),now*pow(p[id],i));
}
else
{
dfs(rest,id+1,sum,now);
}
}
}
return ;
}
void start()
{
MM(dp,0);
for(int i=1;i<20;i++)
{
dfs(i);
}
dp[1]=1;
int temp = 0;
for(int i=1;i<=100;i++)
{
if(temp<dp[i])
{
temp = dp[i];
}
if(dp[i]<temp)
{
dp[i] = temp;
}
}
return ;
}
bool isp(int x)
{
int temp = sqrt(double(x));
for(int i=0;i<p.size();i++)
{
if(!(x%p[i]))
{
return false;
}
if(p[i]>temp)
{
return true;
}
}
return true;
}
int main()
{
p.clear();
p.pb(2);
for(int i=3;i<100;i++)
{
if(isp(i))
{
p.pb(i);
}
}
start();
int T;
int n;
cin>>T;
vector<int>v;
while(T--)
{
cin>>n;
v.clear();
int x = dp[n];
int temp;
int sum=0;
for(int i=0;i<p.size();i++)
{
temp = 1;
while(0 == x%p[i])
{
temp *= p[i];
x/=p[i];
}
if(1 != temp)
{
sum+=temp;
v.pb(temp);
}
}
cout<<dp[n];
for(int i=1;i<=n-sum;i++)
{
cout<<" "<<i;
}
sort(v.begin(),v.end());
temp = n-sum+1;
int top;
for(int i=0;i<v.size();i++)
{
top = temp;
for(int u=1;u<=v[i]-1;u++)
{
temp++;
cout<<" "<<temp;
}
cout<<" "<<top;
temp++;
}
cout<<endl;
}
return 0;
}
pku3590 The shuffle Problem
最新推荐文章于 2019-11-16 17:58:09 发布