zoukankan      html  css  js  c++  java
  • 阶乘质因子分解(唯一分解定理)

    阶乘质因子分解

    题目描述:
    对N!进行质因子分解。
    输入输出格式:
    输入格式:
    输入数据仅有一行包含一个正整数N,N<=10000。
    输出格式:
    输出数据包含若干行,每行两个正整数p,a,中间用一个空格隔开。表示N!包含a个质因子p,要求按p的值从小到大输出。
    输入输出样例
    输入样例#1:
    10
    输出样例#1:
    2 8
    3 4
    5 2
    7 1
    说明
    10!=3628800=(2^8)(3^4)(5^2)*7

    思路:
    因为是n的阶乘:!n=1*2*3……*n所以枚举从1到n的每一个数,然后进行质因数分解。

    #include<iostream>
    using namespace std;
    const int maxn=10010;
    int n,num[maxn];
    void dec(int x)
    {
        for(int i=2;i*i<=x;i++)
        while(x%i==0)
        num[i]++,x=x/i;
        if(x!=1) num[x]++;
    }
    int main()
    {
        cin>>n;
        for(int i=1;i<=n;i++)
        dec(i);
        for(int i=1;i<=n;i++)
        if(num[i])
        cout<<i<<" "<<num[i]<<endl;
        return 0;
    }
  • 相关阅读:
    ubuntu安装netcat
    护网工作
    ssrf绕过
    文件包含绕过
    thinkphp5.0.23
    xxe
    文件上传
    文件上传html xss
    获取网站title
    RobotFramework使用AutoItLibrary输入字符错误问题
  • 原文地址:https://www.cnblogs.com/cax1165/p/6070957.html
Copyright © 2011-2022 走看看