pythonでsqrt(2)の値を10000桁まで求める

Quiz

https://yukicoder.me/problems/no/3006

Submission

https://yukicoder.me/submissions/346488

Code

import decimal
decimal.getcontext().prec = 10000
d = decimal.Decimal(2)
s = str(d.sqrt())
n = str(input())
i = s.find(n)
print(i-1)

自分用メモ

  • ojするなら
oj t -c "python gen.py"
  • Python2だとparseエラーになったりするのでpython3と打ったほうがいいかも *自分が使っているPythonのバージョンを意識する
oj t -c "python3 gen.py"

問題文の復号結果

  • find the first substring equal to the given x from sqrt(2)
  • sqrt(2)からxを探して最初に見つかったindexを返せばよい

C++ならどう解く?