** PREREQUISITES**
OBSERVATION, MATH
EXPLANATION:
Our goal is to maximize the divide by 3 operations, so in each operation, we choose only one number which is a multiple of 3, and divide that number by 3, if no number which is a multiple of 3 is found we discard and stop there and print total operations, so it simply means the sum of log3(value) of each value which is a multiple of 3.
CODE:
#include<bits/stdc++.h>
using namespace std;
int fun(int n)
{
int cnt = 0;
while (n % 3 == 0)
{
cnt++;
n /= 3;
}
return cnt;
}
void solve()
{
int n; cin >> n;
int ans=0;
for(int i=0;i<n;i++)
{
int x;
cin>>x;
ans+=fun(x);
}
cout << ans<<"\n";
}
int main()
{
int t = 1;
cin >> t;
for (int tt = 1; tt <= t; tt++)
{
solve();
}
}