Skip to content

Instantly share code, notes, and snippets.

@danielabrozzoni
Created May 4, 2020 11:00
Show Gist options
  • Save danielabrozzoni/6ff0c1d95e817536df59a46f81df5db0 to your computer and use it in GitHub Desktop.
Save danielabrozzoni/6ff0c1d95e817536df59a46f81df5db0 to your computer and use it in GitHub Desktop.
Given n, find k such that first n digits of 2^k == first n digits of 5^k == first n digits of sqrt(10)
digits = "31622776601683795"
def find(n):
k = 0
last_2 = 1
last_5 = 1
while True:
if first_n_digits(last_2, n) == digits[:n] \
and first_n_digits(last_5, n) == digits[:n]:
return k
last_2 *= 2
last_5 *= 5
k+=1
print(k)
def first_n_digits(n, n_digits):
n_string = f'{n}'
if len(n_string) < n_digits:
return n_string
return n_string[:n_digits]
def main():
print(find(5))
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment