#include <iostream>
using namespace std;
void get_divisors(int x)
{
for(int i=2;i<=x;++i)
if(x%i==0)
{
int s=0;
while(x%i==0) x/=i,s++;
cout<<i<<" "<<s<<'\n';
}
}
int main()
{
int x;
cin>>x;
get_divisors(x);
return 0;
}// 时间复杂度为o(n)
#include <iostream>
using namespace std;
void get_divisors(int x)
{
for(int i=2;i<=x/i;++i)
if(x%i==0)
{
int s=0;
while(x%i==0) x/=i,s++;
cout<<i<<" "<<s<<'\n';
}
if(x>1) cout<<x<<" "<<1<<'\n';
cout<<'\n';
}
int main()
{
int x;cin>>x;
get_divisors(x);
return 0;
}// 时间复杂度为o(sqrt(n))
改代码运用了唯一分解定理