首页 > 代码库 > luogu P2043 质因子分解
luogu P2043 质因子分解
题目描述
对N!进行质因子分解。
输入输出格式
输入格式:
输入数据仅有一行包含一个正整数N,N<=10000。
输出格式:
输出数据包含若干行,每行两个正整数p,a,中间用一个空格隔开。表示N!包含a个质因子p,要求按p的值从小到大输出。
输入输出样例
输入样例#1:
10
输出样例#1:
2 83 45 27 1
说明
10!=3628800=(2^8)*(3^4)*(5^2)*7
质因数分解..
#include<cstdio>const int maxn=100006;int n;int cnt[maxn];int f(int x){ int k=2; while(k*k<=x) { while(x%k==0) { cnt[k]++; x/=k; } k++; } if(x>1)cnt[x]++;}int main(){ scanf("%d",&n); for(int i=2;i<=n;i++) f(i); for(int i=2;i<=n;i++) if(cnt[i]) printf("%d %d\n",i,cnt[i]); return 0;}
luogu P2043 质因子分解
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。