分解质因数

#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;


void divide(int x)
{
    for(int i=2;i<=x/i;i++)
    {
        if(x%i==0)
        {
            int cnt=0;
            while(x%i==0)
            {
                x/=i;
                cnt++;
            }
            cout<<i<<' '<<cnt<<'\n';
        }
    }
    if(x>1)
    {
        cout<<x<<' '<<1<<'\n';
    }
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n;
    cin >> n;
    for(int i=1;i<=n;i++)
    {
        int x;
        cin>>x;
        divide(x);
        cout<<'\n';
    }

    return 0;
}
posted @ 2024-12-27 21:32  闫柏军  阅读(14)  评论(0)    收藏  举报