public void GetFactorsForANumber(int number) { double sqrtVal = Math.Sqrt(number); //round down //int factorValue = 0; for (int i = 1; i <= sqrtVal; ++i) { //test from 1 to the square root, or the int below it, inclusive. if (number % i == 0) { RowColumnFactor rowColObj = new RowColumnFactor(); if (!isPortrait) { rowColObj.row = i; rowColObj.col = number / i; } else { rowColObj.col = i; rowColObj.row = number / i; } // if (!FactorsList.Contains(rowColObj)) FactorsList.Add(rowColObj); } } if (FactorsList.Count == 1) //|| !(d % 1 == 0)) { sqrtVal += 0.5; sqrtVal = Math.Round(sqrtVal, MidpointRounding.AwayFromZero); GetFactorsForPrimeNumber(number, sqrtVal); } }
public void GetFactorsForPrimeNumber(int number, double sqrtVal) { RowColumnFactor rowColObj = new RowColumnFactor(); FactorsList.Add(new RowColumnFactor((int)sqrtVal, (int)sqrtVal)); double squareNumber = Math.Pow(sqrtVal, 2); double count = squareNumber - number; for (int i = 1; i <= count; i++) { int numberParam = number + i; if (squareNumber != numberParam) { GetFactorsForANumber(numberParam); } } }