Description
对 �!N! 进行质因子分解。
Input
输入数据仅有一行包含一个正整数 �N,�≤10000N≤10000。
Output
输出数据包含若干行,每行两个正整数 �,�p,a,中间用一个空格隔开。表示 �!N! 包含 �a 个质因子 �p,要求按 �p 的值从小到大输出。
Sample 1
Inputcopy | Outputcopy |
---|---|
10 | 2 8 3 4 5 2 7 1 |
Hint
10!=3628800=(28)×(34)×(52)×710!=3628800=(28)×(34)×(52)×7。
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#define endl '\n'
#define ll long long
#define int ll
using namespace std;
const int N=1e6+7;
map<int,int> mp;
signed main()
{
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int n;
cin>>n;
for(int k=n;k>=1;k--)
{
int temp=k;
for(int i=2;i*i<=n;i++)
{
while(temp%i==0)
{
mp[i]++;
temp/=i;
}
}
if(temp!=1) mp[temp]++;
}
for(auto it=mp.begin();it!=mp.end();it++)
{
cout<<it->first<<' '<<it->second<<endl;
}
return 0;
}