c - Some numbers take longer to factor than others -


can tell me reason number 104751475143 computed in less second while number 251475141 takes longer amount of time? code trying find largest factor.

this code.

    long long lrgpfactor = 0;     long long currentfactor = 0;     long long tempfactor = 0;     long long number =  251475141;     long long factor = 0;       switch ((long long)sqrt(number)%2) //skipping square root of number save time {      case 0: factor=((long long)sqrt(number)-1); break; //if make odd     default: factor=((long long)sqrt(number)); break; //if odd leave }     while (factor > 0)  {         if (number % factor == 0) //if factor factor        {             factor=number/factor; //make factor larger of pair         switch ((long long)sqrt(factor)%2) //same above             {                  case 0: tempfactor=((long long)sqrt(factor)-1); break;                  default: tempfactor=((long long)sqrt(factor)); break;              }               (tempfactor = factor - 1; tempfactor > 1; --tempfactor) //simple way determine if prime             {             if (factor % tempfactor == 0)                     break;             }             if (tempfactor == 1)             {                lrgpfactor = factor;                break;            }         }         factor -= 2; } 

it takes longer because prime factor of 104751475143 391751 , 104751475143/391751=267393 closer square root of 104751475143 3 (3=251475141/83825047) close square root of 251475151. must run through more iterations of loop.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -