B整数因子分解问题

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/wangqiao05/article/details/89358526

整数因子分解问题

Time Limit: 1000 ms Memory Limit: 65536 KiB

Submit Statistic

Problem Description

大于1的正整数n可以分解为:n=x1*x2*…*xm。例如,当n=12 时,共有8 种不同的分解式: 
12=12; 
12=6*2; 
12=4*3; 
12=3*4; 
12=3*2*2; 
12=2*6; 
12=2*3*2; 
12=2*2*3。
对于给定的正整数n,计算n共有多少种不同的分解式。

Input

输入数据只有一行,有1个正整数n (1≤n≤2000000000)。

Output

将计算出的不同的分解式数输出。

Sample Input

12

Sample Output

8

#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int a[10000], b[10000], k;

void yue(int n)
{
    k = 0;
    for(int i = 1; i < sqrt(n); i++)
    {
        if(n % i == 0)
        {
            a[k] = i;
            k++;
            a[k] = n / i;
            k++;
        }
    }
}

void ll()
{
    b[0] = 1;
    for(int i = 1; i < k; i++)
    {
        b[i] = 0;
        for(int j = 0; j < i; j++)
        {
            if(a[i] % a[j] == 0)
            {
                b[i] += b[j];
            }
        }
    }
}


int main()
{
    int n;
    cin >> n;
    yue(n);
    sort(a, a+k);
    ll();
    cout << b[k-1];
    return 0;
}
 

猜你喜欢

转载自blog.csdn.net/wangqiao05/article/details/89358526