算法笔记.分解质因数

代码实现:

#include
using namespace std;
void breakdown(int x)
{
    int t = x;
    for(int i = 2;i <= x/i;i++)
    {
        if(t%i == 0)
        {
            int counts = 0;
            while(t % i == 0)
           {
               t/=i;
               counts++;
           }
           cout << i <<" "<< counts< 1) cout << t <<" " << 1<>n;
    while(n--)
    {
        int x;
        scanf("%d",&x);
        breakdown(x);
    }
    
    return 0;
}

性能:

将时间复杂度降为\sqrt{x} 

你可能感兴趣的:(算法,笔记,c++)