思路:
利用n = 3的情况,当n = 3,输出169,196,961,推广到所有奇数n的情况:
构造方法为 1 + i个0 + 6 + i个0 + 9 + (n - 2 * i - 3)个0,因为n为奇数,所以n - 2 * i - 3为偶数,该方法可以构造 n / 2个数,同理,把169改成196也可以构造 n / 2 个数,再加上961 + (n - 3)个0 就是n个数。
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int maxn = 2e5 + 5;
int a[maxn];
void solve(){
int n;
cin >> n;
if(n == 1){
cout << "1\n";
}
else if(n == 3){
cout << "169\n196\n961\n";
}
else{
cout << "196" << string(n - 3, '0') << '\n';
for(int i = 0; i < n / 2; i++){
cout << 1 << string(i, '0') << 6 << string(i, '0') << 9 << string(n - 2 * i - 3, '0') << '\n';
cout << 9 << string(i, '0') << 6 << string(i, '0') << 1 << string(n - 2 * i - 3, '0') << '\n';
}
}
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
int T = 1;
cin >> T;
while(T--){
//cout << T << ":\n";
solve();
}
return 0;
}