Sherlock and The Beast

  • + 0 comments

    You could just change the constants in this simple algorithm. A solution is guaranteed (for large enough numbers of digits) whenever the two constants are coprime (no common prime factors). If the problem merited it (larger constants), you could use the Extended Euclidean Algorithm to calculate, but that would require some understanding of modular arithmetic.

        numFives = numDigits - (numDigits % 3);
        numThrees = numDigits - numFives;
        while (numThrees % 5)
            numThrees += 3;
        numFives = numDigits - numThrees;