[解题报告]《算法零基础100讲》(第11讲) 因子数

The number of divisors(约数) about Humble Numbers

在这里插入图片描述

分析:
这道题其实是叫我们求一个数的质因数2, 3, 5, 7的个数,所以我们可以根据公式,求出每个因子数量,然后进行乘积。
公式如下:
在这里插入图片描述在这里插入图片描述
代码:

#include <iostream>

using namespace std;

int main(){
    
    
    long long n = 1;
    int arr[] = {
    
     2, 3, 5, 7 };
    while (cin >> n && n != 0){
    
    
        int num = 1;
        for (int i = 0; i < 4; i++){
    
    
            int cout = 0;
            for (; n % arr[i] == 0; n /= arr[i])cout++;
            num *= cout + 1;
        }
        cout << num << endl;
    }
}

猜你喜欢

转载自blog.csdn.net/qq_53060585/article/details/121070692