Description
Input
Output
Sample Input
10
Sample Output
4 1 2 3 4
#include<iostream> #include<algorithm> #include<cstdio> #include<cstring> #include<string> using namespace std; typedef long long ll; int main() { ll k; while(cin >> k) { if(k <= 1e5) { cout <<k << endl; for(int i = 1; i <= k; i++) { printf( "1" ); if(i == k) printf( "\n" ); else printf( " " ); } continue; } ll a, b, c=0; int flag = 0; while(1) { ll s = k + c*c + c + 1; for(int i = c + 1; i*i <= s; i++) { a = i; if(s%a != 0)continue; b = s / a; if(b < c + 1)continue; if(a + b - c - 2 <= 1e5) { flag = 1; break; } } if(flag) break; else c++; } cout << a + b - c - 2 << endl; for(int i = 1; i <= a - c - 1; i++) printf( "1 " ); for(int i = 1; i < b - c - 1; i++) printf( "2 " ); if(c == 0) printf( "2\n" ); else { printf( "2 " ); for(int i = 1; i < c; i++) printf( "3 " ); printf( "3\n" ); } } return 0; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
解题报告 之 HDU5334 Virtual Participation
原文地址:http://blog.csdn.net/maxichu/article/details/48027237