Last active
June 10, 2019 01:40
-
-
Save Radcliffe/2e0a1810dca175e91dd77c50db1f4b44 to your computer and use it in GitHub Desktop.
Least k such that k*n and (k+1)*n fail to have a common nonzero digit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This script calculates Sequence A0308479, the least k such that k*n and (k+1)*n | |
# fail to have a common nonzero digit, or 0 if this property never occurs. | |
# | |
# See: https://oeis.org/A308479 | |
# | |
# Author: David Radcliffe | |
# 9 June 2019 | |
def share_digit(m, n): | |
return set(str(m)) & set(str(n)) - set('0') | |
def a308479(n): | |
m = len(str(n)) + 1 | |
for k in range(1, 10 ** m // n + 1): | |
if not share_digit(k * n, (k + 1) * n): | |
return k | |
remainders = set() | |
rem = pow(10, m, n) | |
P = 10 ** m | |
for p in range(m, m + n + 1): | |
if rem in remainders: | |
return 0 | |
remainders.add(rem) | |
N = -1 | |
for a in range(1, 10): | |
N += P | |
k = N // n | |
kn = k * n | |
if not share_digit(kn, kn + n): | |
return k | |
rem = (10 * rem) % n | |
P *= 10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment