You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

546 B

2的幂整除

一、题目描述

给一个正整数n,计算它最多能被2的多少次幂整除

输入格式 输入一个数 n

输出格式 输出一个数

输入样例 896

输出样例 7

二、实现代码

#include <iostream>
using namespace std;
/*
896

7
*/
int main() {
    int n;
    cin >> n;
    int b = 2;
    int cnt = 0;
    while (n % b == 0) {
        b *= 2;
        cnt++;
    }
    printf("%d", cnt);

    return 0;
}