題意:
給定一串序列,要求對其中每個數進行除2或乘3的操作,但是不能將每個數都乘3,問最多幾步讓這個序列所有數都變爲奇數。
思路:
一個一個輸入,不用按數組讀入,碰到偶數,就除二,res++,變爲奇數就停。
本人AC代碼:
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
int n;
int num;
int res;
int main() {
cin >> n;
while(n--) {
cin >> num;
while(!(num & 1)) {
num /= 2;
res++;
}
}
cout << res << endl;
}