求质因数

#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
int n;

bool check(int n)
{
    for (int i = 2; i <= n / i; i++)
    {
        int s = 0;
        while (n)
        {
            cout << n << endl;
            n /= i;
            s++;
        }
        cout << i << " " << s << endl;
    }
    if (n > 1)
        cout << n << " " << 1 << endl;
    cout << endl;
    return true;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    int x;
    while (n--)
    {
        cin >> x;
        check(x);
    }
    return 0;
}
发布了103 篇原创文章 · 获赞 203 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/qq_45432665/article/details/104428193