#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <bitset>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
const int maxn = 1111;
const int N = 1111;
const double eps = 1e-8;
int a[N], b[N], d[N];
int x[N], y[N];
void go(int i, int a[]) {
int j, k, t;
for (k = 0; k < 10; ++k) {
t = a[i] + k * a[0] * 2;
if (t % 10 == k) {
for (j = 0; j < i; ++j)
a[j + i] += a[j] * k * 2;
a[i + i] += k * k;
for (j = 0; j < maxn; ++j)
a[j + 1] += a[j] / 10, a[j] %= 10;
break;
}
}
}
void print(int n, int a[]) {
if (!a[n - 1])
return;
putchar(' ');
for (int i = n - 1; i >= 0; --i)
printf("%d", a[i]);
}
int main() {
ios::sync_with_stdio(false);
a[0] = 5;
b[0] = 6;
a[1] = 2;
b[1] = 3;
int i, j, k, t;
for (i = 1; i < 502; ++i) {
go(i, a);
go(i, b);
}
int T;
scanf("%d", &T);
for (int cas = 1; cas <= T; ++cas) {
scanf("%d", &k);
printf("Case #%d:", cas);
if (k == 1)
puts(" 0 1 5 6");
else {
t = 0;
t += (a[k - 1] > 0);
t += (b[k - 1] > 0);
if (!t)
puts("Impossible");
else {
t = 0;
for (j = k - 1; j >= 0; --j) {
if (a[j] < b[j])
t = 1;
if (a[j] > b[j])
t = 2;
if (t)
break;
}
if (t == 1)
print(k, a), print(k, b);
if (t == 2)
print(k, b), print(k, a);
puts("");
}
}
}
return 0;
}
UVA 12009 - Avaricious Maryanna
最新推荐文章于 2024-06-25 17:28:58 发布