Skip to content

Instantly share code, notes, and snippets.

@uchidama
Created July 29, 2021 15:28
Show Gist options
  • Save uchidama/76d1c927d5227bbccf42c135b183acb5 to your computer and use it in GitHub Desktop.
Save uchidama/76d1c927d5227bbccf42c135b183acb5 to your computer and use it in GitHub Desktop.
AtCoder Beginner Contest 166 [ D - I hate Factorization ] https://atcoder.jp/contests/abc166/tasks/abc166_d
'''
[問題]
https://atcoder.jp/contests/abc166/tasks/abc166_d
[参考]
https://blog.hamayanhamayan.com/entry/2020/05/03/224316
 ここのコードをPythonコンバートしてみたもの。
 5乗の結果をキャッシュしてるから早いかと思ったら、普通に計算したのと変わらない。
[結果]
PyPy3 Ac 72ms
'''
import sys
sys.setrecursionlimit(10 ** 6) # 再帰上限の引き上げ
input = sys.stdin.readline
INF = 2 ** 63 - 1
X = int(input())
# 5乗の結果をキャッシュ
F = {}
for i in range(-1000, 1001):
F[i**5] = i
# A^5 - B^5 = Xから、B^5 + Xの値が存在するならば、Aがあるはず
for B5, B in F.items():
key = B5 + X
if key in F:
A = F[key]
print(A, B)
exit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment