Find the largest prime number factor?

前端 未结 7 1826
别那么骄傲
别那么骄傲 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:35

    In order to do this you need to establish that the value is prime - i.e. that is has no prime factors.

    Now your little piece of code checking 3/5/7 simply isn't good enough - you need to check is value has ANY lower prime factors (for example 11/13/17).

    From a strategic perspective if you want to use this analysis you need to check a list of every prime factor you have found so far and check against them as you are checking against the first 3 primes.

    An easier (but less efficient) method would be to write an IsPrimeFunction() and check the primality of the each divisor and store the largest.

提交回复
热议问题