All pastes #769846 Raw Edit

Miscellany

public c v1 · immutable
·published 2007-11-11 18:38 UTC
rendered paste body
int primefactors(int length){  int intToTest = length;  int nrOfFactors = 0, i = 0, factor_01 = 0;  int maxVal=(int)sqrt(length);   if (length<2)    return 0;  for (i = 2; intToTest > 1 && nrOfFactors <3 && i<=maxVal; i++)  {    while ((intToTest%i)==0)    {      factor_01 = i;      intToTest /= i;      nrOfFactors++;    }  }  if (nrOfFactors == 0) //one factor found (prime itself) ==> prime    return -2;  if (nrOfFactors == 2) //if there are exactly two factors    return factor_01;  if (nrOfFactors > 2) //if there are more than 2 factors    return -3;  return 0;}