SDUT ACM-1722 整数因子分解问题

整数因子分解问题

Time Limit: 1000 ms Memory Limit: 65536 KiB

Problem Description
大于1的正整数n可以分解为:n=x1x2…*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 <bits/stdc++.h>

using namespace std;

const int mid=10001;

int a[mid];

int yinzi(int n)
{
    int f=1;
    if(n<mid&&a[n]!=0)
        return a[n];

    for(int i=2;i<=sqrt(n);i++)
    {
        if(n%i==0)
        {
            if(i*i==n)
            {
                f=f+yinzi(i);
            }
            else
            {
                f=f+yinzi(i)+yinzi(n/i);
            }
        }
    }

    if(n<mid)
        a[n]=f;
    return f;
}

int main()
{
    int n;
    memset(a,0,sizeof(a));
    cin>>n;

    cout<<yinzi(n)<<endl;


    return 0;
}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值