AcWing 867. 分解质因数


#include <bits/stdc++.h>
using namespace std;
int n;
void divided(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<<endl;  
            }

        }
        //唯一一个大于sqrt(x)的质因数,指数只能为1
        if(x>1) cout<<x<<' '<<1<<endl;
        puts("");
}

int main(){
    cin>>n;
    while(n--){
        int x;
        scanf("%d",&x);
        divided(x);
    }
    return 0;
}