思路:
贪心乱搞。
实现:
1 #include <bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 5 const ll m = 1e13; 6 7 ll a[100005], b[100005]; 8 9 bool check(ll x) 10 { 11 ll s = sqrt(x); 12 return s * s == x; 13 } 14 15 int main() 16 { 17 int n; 18 while (cin >> n) 19 { 20 for (int i = 1; i <= n / 2; i++) cin >> a[i]; 21 ll p = 1; 22 while (p * p <= m && !check(p * p + a[1])) p++; 23 if (p * p > m) { cout << "No" << endl; continue; } 24 b[1] = p * p; 25 ll sum = b[1] + a[1]; 26 int i = 2; 27 for ( ; i <= n / 2; i++) 28 { 29 while (p * p <= sum + m && (p * p <= sum || !check(p * p + a[i]))) p++; 30 if (p * p > sum + m) break; 31 b[i] = p * p - sum; sum = p * p + a[i]; 32 } 33 if (i != n / 2 + 1) { cout << "No" << endl; continue; } 34 cout << "Yes" << endl; 35 for (int i = 1; i <= n / 2; i++) cout << b[i] << " " << a[i] << " "; 36 cout << endl; 37 } 38 }