这题不用做的这么麻烦吧。直接计数就行了。能被1,2,4整除的数分别是多少再判断就行了。
不过我的做法90%,不知道哪个case没过...
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstdint>
#include <vector>
#include <stack>
#include <algorithm>
#include <unordered_map>
#include <cmath>
#include <cstring>
#include <queue>
#include <set>
using namespace std;
#define MAX 100005
#define MOD 1000000007
#define LL long long int
int t, n;
LL nums[MAX];
//vector<int> a1, a2, a4;
int a1,a2,a4;
bool check(LL a, LL b){
return ((a * b) & 3) == 0;
}
int main()
{
#ifdef DEBUG
freopen("input.txt","r",stdin);
#endif
scanf("%d",&t);
while(t --){
scanf("%d",&n);
//a1.clear();
//a2.clear();
//a4.clear();
a1 = a4 = a2 =0;
for (int i =0;i< n;i++){
scanf("%lld",&nums[i]);
if (nums[i] %4 == 0)
a4++;
else if ( nums[i]%2 == 0)
a2 ++;
else
a1 ++;
}
if (n == 1){
printf("No\n");
continue;
}
if (a1-1 > a4 || (a1 > 0 && a4 == 0)){
printf("No\n");
continue;
}
if (a1 == 0 || a2 == 0){
printf("Yes\n");
continue;
}
if (a1 > a4){
printf("No\n");
continue;
}
printf("Yes\n");
/*
if ((a4< a1-1) || (a1 >0 && a4 == 0)){
printf("No\n");
continue;
}
if ((a2 >0) && a4 < a1 ) {
printf("No\n");
continue;
}*/
}
return 0;
}