Solution
设数组的第一个数为 ,因为除了其中第一个数字以外其它数字都等于前面所有数字的和,所以第二个数就为 ,第三个数为 ,依此类推,从第二个数起,第 个数为 。 因为我们要让 最小,所以要让 在这个数组中的位置最靠后。于是就可以让 不断除以 ,直到不是偶数为止,放在第一个。
Code
#include<bits/stdc++.h>
#define int long long//记得开long long
using namespace std;
const int inf = 0x3f3f3f3f,mod = 1e9 + 7;
const int maxm = 20 + 7;
int t,n,x;
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cin >> t;
while(t--){
cin >> n >> x;
int cnt = 2,y = x;//第一个数和第二个数一样,cnt可以从2开始
while(y % 2 == 0 && cnt <= n)//x中2的个数不能超过n
y /= 2,cnt++;
while(cnt < n)
x *= 2,cnt++;
cout << x << endl;
}
return 0;
}