AcWing 867. 分解质因数
原题链接
简单
作者:
术
,
2021-01-31 10:56:01
,
所有人可见
,
阅读 200
#include <iostream>
#include <map>
#include <algorithm>
using namespace std;
int main()
{
int n;
cin>>n;
while(n--)
{
map<int,int> primes;
int x;
cin>>x;
for(int i=2; i<=x/i; i++)
{
if(x%i==0)
while(x%i==0)
{
primes[i]++;
x/=i;
}
}
if(x>1) primes[x]++;
map<int,int>::iterator it;
for(it=primes.begin(); it!=primes.end(); it++)
{
cout<<it->first<<" "<<it->second<<endl;
}
cout<<endl;
}
//cout << "Hello world!" << endl;
return 0;
}