#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;
}
分享到:
相关推荐
pku acm 2752 Seek the Name, Seek the Fame代码 kmp算法。解题报告:http://blog.csdn.net/china8848
Codes of PKU_ACM OnlineJudge Problem
Now the only thing the house misses is a cute little wooden fence. He had no idea how to make a wooden fence, so he decided to order one. Somehow he got his hands on the ACME Fence Catalogue 2002, ...
pku acm 1050 To the Max代码,有详细注释,动态规划
pku acm 1274 The Perfect Stall 代码 二分图的最大匹配的匈牙利算法 解题报告请访问:http://blog.csdn.net/china8848
pku部分题代码,不多,试一下怎么上传文件!
Despite the fact that many 3D human activity benchmarks being proposed, most existing action datasets focus on the action recognition tasks for the segmented videos. There is a lack of standard large-...
pku1000 pku1000程序 解题报告
pku经典题目解题报告 pku经典题目解题报告
Pku acm 第1163题 The Triangle 代码,有详细的注释,动态规划
我写的解题报告,关于度限制生成树的 网址:http://acm.pku.edu.cn/JudgeOnline/problem?id=1639<br>题目:Picnic Planning 来源:East Central North America 2000
pku1664源代码
PKU JudgeOnline FAQ 中文版 常见问题解答
Pku acm 第1887题 Testing the CATCHER 代码,有详细的注释,动态规划
8数码代码pku1077,300ms(哈希+广度搜索)
ppt word PKU 课件 五星级灰常强大
ACM代码 北大pku。 搞ACM的可以参考一下。代码还是挺规范的。有接近150道题目的代码。
PKU 2339 Rock, Scissors, Paper 源代码
有一些代码是pku上的,希望大家看后给我留言,看看我的代码那里有问题??
pku acm 1469 COURSES 代码 二分图的最大匹配的匈牙利算法 解题报告请访问:http://blog.csdn.net/china8848