An explanation: if n² ends in n, then n² - n ends in as many zeroes as there are digits in n. I'm not going to prove this here, I believe it is pretty straightforward. If a number ends in m zeroes, then the number is divisible (remainder of 0) by 10m.
The test now is: is n² - n divisible by 10 ^ (number of digits in n). Finding the number of digits is simple: the log base 10 of a number with m digits is m - x, x is in the interval (0,1]. This translates to floor(log base 10 of n) + 1 = number of digits.
So that's my solution.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Solution without strings (Haskell)
An explanation: if n² ends in n, then n² - n ends in as many zeroes as there are digits in n. I'm not going to prove this here, I believe it is pretty straightforward. If a number ends in m zeroes, then the number is divisible (remainder of 0) by 10m.
The test now is: is n² - n divisible by 10 ^ (number of digits in n). Finding the number of digits is simple: the log base 10 of a number with m digits is m - x, x is in the interval (0,1]. This translates to floor(log base 10 of n) + 1 = number of digits.
So that's my solution.