How to find the largest prime factor of 600851475143?

前端 未结 5 1075
挽巷
挽巷 2021-01-16 19:08
#include 
main()
{
    long n=600851475143;
    int i,j,flag;
    for(i=2;i<=n/2;i++)
    {
        flag=1;
        if(n%i==0)//finds factors backw         


        
5条回答
  •  北恋
    北恋 (楼主)
    2021-01-16 19:57

    One potential problem is that i and j are int, and could overflow for large n (assuming int is narrower than long, which it often is).

    Another issue is that for n=600,851,475,143 your program does quite a lot of work (the largest factor is 6857). It is not unreasonable to expect it to take a long time to complete.

提交回复
热议问题