public static BigInteger sevenZero(int n) {
// Since seven is a famously lucky number in Western culture, whereas zero is what nobody wants to be, let us look at those positive integers whose digits consist of some sequence of sevens, followed by some (possibly empty) sequence of zeros. For example, 0, 7, 77777, 7700000, 77777700, or 70000000000000000000000000000000000. Note that all sevens must be in one consecutive bunch, followed by all zeros in another consecutive bunch.
// One of the examples of combinatorial thinking given in the excellent MIT online textbook "Mathematics for Computer Science" (PDF link to the updated 2018 version, for anybody who is interested in that sort of stuff) points out that for any positive integer n, there exists at least one positive integer thus constrained to sevens and zeros that is divisible by n. This integer made of sevens and zeros always exists for any integer n.
// This method should find and return the smallest such integer that is divisible by the given n. The easiest way to do this would be to use two nested loops. The outer while-loop iterates through all possible lengths (that is, how many digits the number contains) of the number, and for each length, the inner for-loop iterates through all legal sequences of sevens followed by zeros of that total length. Keep going up until you find such a number that is exactly divisible by n.
// This process will always eventually terminate for any n, since such a number is always guaranteed to exist, although these numbers can easily become gargantuan. For example, for the argument value n = 12345, the resulting number consists of 822 copies of the digit seven followed by a single zero digit. To speed up the search, you can utilize an additional theorem given in the same book, that says that unless n is divisible by either 2 or 5, the sequence of sevens and zeros that is divisible by n is guaranteed to contain only sevens but no zeros. This ought to speed up your search by at least an order of magnitude for such easy values of n, since the quadratic number of possibilities is pruned down into a single linear branch 7, 77, 777, 7777, ...
}