题意:
给定一串序列,要求对其中每个数进行除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;
}