Use set of codeforces B. Make Them Odd -C ++ stl of

B. Make Them Odd

There are nn positive integers a1,a2,,ana1,a2,…,an. For the one move you can choose any even value cc and divide by two all elements that equal cc.

For example, if a=[6,8,12,6,3,12]a=[6,8,12,6,3,12] and you choose c=6c=6, and aa is transformed into a=[3,8,12,3,3,12]a=[3,8,12,3,3,12] after the move.

You need to find the minimal number of moves for transforming aa to an array of only odd integers (each element shouldn't be divisible by 22).

Input

The first line of the input contains one integer tt (1t1041≤t≤104) — the number of test cases in the input. Then tt test cases follow.

The first line of a test case contains nn (1n21051≤n≤2⋅105) — the number of integers in the sequence aa. The second line contains positive integers a1,a2,,ana1,a2,…,an (1ai1091≤ai≤109).

The sum of nn for all test cases in the input doesn't exceed 21052⋅105.

Output

For tt test cases print the answers in the order of test cases in the input. The answer for the test case is the minimal number of moves needed to make all numbers in the test case odd (i.e. not divisible by 22).

Example

4
6
40 6 40 3 20 1
1
1024
4
2 4 8 16
3
3 1 7

output

4
10
4
0

  It is used in c ++ STL violence before, with a set container, he is characterized by the individual elements is unique, compared to the map, set also supports custom sorting, int default is ascending order, characters are arranged in order according to the dictionary

Details can be seen using the set: https: //blog.csdn.net/byn12345/article/details/79523516

Needless to say violent direct look at the code (with comments):

//https://blog.csdn.net/sinat_37158899/article/details/79328104 
#include <. bits / STDC ++ H> 
the using namespace STD; 
int A [200005]; 
BOOL CMP (A int, int B) 
{ 
	return A > B; 
} 
struct CMP2 
{ 
	BOOL operator () (int const A, const int B) 
	{ 
		return A> B; // descending 
	} 
}; 
SET <int, CMP2> SS; // default from small to large, the string in alphabetical order. 
int main (void) 
{ 
	int T, n-; 
	Scanf ( "% D", & T); 
	the while (T--) 
	{ 
		Scanf ( "% D", & n-); 
		for (int I =. 1; I <= n-; ++ I) { 
			Scanf ( "% D", A & [I]); 
		} 
		Sort (. 1 + A, + n-A +. 1, CMP); 
		
		int Top = 0; int In Flag = 0;
		
		for(int i=1;i<=n;i++){
			if(a[i]!=a[i-1]&&a[i]%2==0)
			ss.insert(a[i]),flag=1;
		}
		long long int ans=0;
		set<int>::iterator it;
		//printf("svdsvf\n");
		while(flag)
		{
			flag=0;
			//for(it=ss.begin();it!=ss.end();it++) printf("%d ",*it);
			//printf("\n");
			for(it=ss.begin();it!=ss.end();it++){
				if(*it%2==0)
				{
					flag=1;
					ans++;
					int san=*it;
					ss.erase(san);
					san/=2;
					//printf("没有失效:%d\n",*it);//set的it也会失效 ,vector的会 
					//注意不要使用过期的iterator 
					if(san%2==0)
					ss.insert(san);
					break;
				}
			}
		}
		printf("%lld\n",ans);
	}
	return 0;
}

  

Guess you like

Origin www.cnblogs.com/xuanmaiboy/p/12041611.html