#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
const int MAX=1e7;
bool isprime[MAX];
int prime[MAX];
int num;
void get_prime()
{
memset(isprime,true,sizeof(isprime));
long long i,j;
for( i = 2 ;i < MAX ;i ++)
{
if(isprime[i]==true)
{
for( j = i*i; j< MAX ;j +=i)
isprime[j]=false;
}
}
num=0;
for( i = 2 ;i< MAX ; i ++)
{
if(isprime[i]==true)
{
prime[num++]=i;
}
}
}
int factor_num[100][2];
void factor(int n)
{
memset(factor_num,0,sizeof(factor_num));
int m=n;
num=0;
for(int i=0; prime[i]*prime[i]<=m ;i ++)
{
if(m%prime[i]==0)
{
factor_num[num][0]=prime[i];
factor_num[num][1]++;
m/=prime[i];
while(m%prime[i]==0)
{
factor_num[num][1]++;
m/=prime[i];
}
num++;
}
}
if(m>1)
{
factor_num[num][0]=m;
factor_num[num][1]=1;
num++;
}
}
int main()
{
get_prime();
int n;
while(~scanf("%d",&n))
{
factor(n);
for(int i=0;i<num;i++)
{
cout<<factor_num[i][0]<<" "<<factor_num[i][1]<<endl;
}
}
return 0;
}
素因子分解
最新推荐文章于 2021-07-18 09:47:54 发布