整數因子分解問題

Home
Contests
Experiments
Problems
Status
Ranklist
Logout
整數因子分解問題
Time Limit: 1000 ms Memory Limit: 65536 KiB
Submit Statistic
Problem Description

大於1的正整數n可以分解爲:n=x1x2xm。例如,當n=12 時,共有8 種不同的分解式:
12=12;
12=6
2;
12=43;
12=3
4;
12=322;
12=26;
12=2
32;
12=2
2*3。
對於給定的正整數n,計算n共有多少種不同的分解式。
Input

輸入數據只有一行,有1個正整數n (1≤n≤2000000000)。
Output

將計算出的不同的分解式數輸出。
Sample Input

12
Sample Output

8
Hint

Source

SDUTACM運維技術中心
Fri Nov 22 2019 10:35:32 GMT+0800 (CST)
Copyright © 2013-2017 SDUTACM Team. All Rights Reserved.

#include<bits/stdc++.h>
using namespace std;
int n,sum=1;
void solve(int n)
{
    for(int i=2;i<=sqrt(n);i++)
    {
        if(n%i==0)
        {
            solve(i);
            if(i*i!=n)//如果兩個數不相同
            {
                sum=sum+2;//交換兩個數的順序則有兩種
                solve(n/i);
            }
            else sum++;//否則兩數相同則只有一種
        }
    }
}
int main()
{
    cin>>n;
    solve(n);
    cout<<sum;
    return 0;
}


發佈了126 篇原創文章 · 獲贊 10 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章