-
Notifications
You must be signed in to change notification settings - Fork 0
/
meta.cpp
100 lines (85 loc) · 1.85 KB
/
meta.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include <bits/stdc++.h>
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <unordered_map>
#include <map>
#include <unordered_set>
#include <set>
#include <iomanip>
using namespace std;
#define fast \
{ \
ios_base::sync_with_stdio(false); \
cin.tie(nullptr); \
cout.tie(nullptr); \
}
#define int long long
#define ld long double
#define f(n) for (auto i = 0; i < n; i++)
const int M = 1000000007;
const int N = 100005;
void IO();
vector<int> ans;
void solve(int sum, int n, vector<int> &temp)
{
if (ans.size() && (ans.size() <= temp.size()))
return;
if (sum < 0 || n < 1)
return;
if (n == 1)
{
if (ans.size() && (ans.size() <= temp.size() + sum))
return;
vector<int> x = temp;
for (int i = 0; i < sum; i++)
x.push_back(1);
ans = x;
if (ans.size() || (ans.size() < x.size()))
return;
}
for (int i = 41; i >= 2; i--)
{
if (n % i || sum < i)
continue;
temp.push_back(i);
solve(sum - i, n / i, temp);
temp.pop_back();
}
}
int32_t main()
{
fast
IO();
int t;
cin >> t;
int cnt = 1;
while (t--)
{
cout << "Case #" << cnt++ << ": ";
int n;
cin >> n;
vector<int> temp;
ans.clear();
solve(41, n, temp);
if (ans.empty())
{
cout << -1 << endl;
continue;
}
cout << ans.size() << " ";
for (auto it : ans)
cout << it << " ";
cout << endl;
}
}
void IO()
{
#ifndef ONLINE_JUDGE
freopen("abcd.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}