/// <summary> /// https://projecteuler.net/problem=64 /// </summary> /// <param name="arguments"></param> /// <returns></returns> public static Result OddPeriodSquareRoots(Problem arguments) { var count = 0; var upperBound = arguments.IntNumber; for (int n = 2; n <= upperBound; n++) { if (UtilityMath.IsPerferctSquare(n)) { continue; } var p = UtilityMath.GetContinuedFractionExpansionPeriodicLengthForNonPerfectSquare(n); if (p % 2 == 1) //only if odd { count++; } } var answer = count.ToString(); var message = string.Format("The number of continued fractions for N ≤ {0} have an odd period is {1}.", upperBound, answer); if (Answers[arguments.Id] != answer) { message += string.Format(" => INCORRECT ({0})", Answers[arguments.Id]); } var r = new Result(arguments.Id, message) { Answer = answer }; return(r); }