Finding prime factors

前端 未结 12 468
北海茫月
北海茫月 2020-12-29 14:24
#include 
using namespace std;

void whosprime(long long x)
{
    bool imPrime = true;

    for(int i = 1; i <= x; i++)
    {
        for(int z =          


        
12条回答
  •  有刺的猬
    2020-12-29 15:10

    Try this code. Absolutely it's the best and the most efficient:

    long long number;
    bool isRepetitive;
    
    for (int i = 2; i <= number; i++) {
        isRepetitive = false;
        while (number % i == 0) {
            if(!isRepetitive){
                cout << i << endl;
                isRepetitive = true;
            }
            number /= i;
        }
    }
    

    Enjoy! ☻

提交回复
热议问题