下面代码用于统计 n 中因子 2 出现了多少次。若 n= 40,输出是
int n= 40; int cnt= 0; while(n% 2== 0){ cnt++; n/= 2; } cout<< cnt;
1
2
3
4