Find the largest prime number factor?

前端 未结 7 1762
别那么骄傲
别那么骄傲 2021-01-29 08:40

I need to find The prime factors of 13195 are 5, 7, 13 and 29. / * Largest is 377. * / What is the largest prime factor of the number 600851475143 ?

#include<         


        
7条回答
  •  南方客
    南方客 (楼主)
    2021-01-29 09:23

    #include
    //Euler problem #3
    int main(){
        long long i, sqi;
        long long value, large = 600851475143LL;
        long long max = 0LL;
    
        i   = 2LL;
        sqi = 4LL; //i*i
        for(value = large; sqi <= value ; sqi +=  2LL * i++ + 1LL){
            while(value % i == 0LL){
                value /= (max=i);
            }
        }
    
        if(value != 1LL && value != large){
            max = value;
        }
        if(max == 0LL){
            max = large;
        }
        printf("%lld\n", max);
        return 0; 
    }
    

提交回复
热议问题