Print all unique combination of factors of a given number

后端 未结 9 738
挽巷
挽巷 2021-02-08 05:46

What is the most efficient algorithm to print all unique combinations of factors of a positive integer. For example if the given number is 24 then the output should be

9条回答
  •  醉酒成梦
    2021-02-08 06:17

    bool isprime(int n){
    for(int i=2; i<=sqrt(n); i++)
        if(n%i==0)
            return false;
    return true;
    }
    
    void printprime(int n){
    
    int i,j,y=n;
    
    while(y%2==0){
        cout<<"2 * ";
        y/=2;
    }
    
    for(i=3; i<=sqrt(y); i+=2){
        while(y%i==0){
            cout<2)
        cout< done;
    
    for(i=2; i

提交回复
热议问题