結果

問題 No.2189 六平方和
ユーザー FromBooskaFromBooska
提出日時 2023-06-02 15:50:53
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,836 bytes
コンパイル時間 597 ms
コンパイル使用メモリ 81,920 KB
実行使用メモリ 380,484 KB
最終ジャッジ日時 2024-12-28 15:38:46
合計ジャッジ時間 13,376 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 22 WA * 3 TLE * 3
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#
# M**N (mod B) = Rpow
# xi**2 (mod B)0 for xi=B, or 1 for xi=1
# x1Rx1**2 (mod B)x1
# x2, x3
# Yes
# WA
#
# NO
# 2x
N, M, B = map(int, input().split())
R = pow(M, N, B)
R_remainder = R
INF = 10**20
X = []
for i in range(3):
#print('i', i, 'R_remainder', R_remainder, X)
if R_remainder == 0:
X.append(B)
continue
diff = INF
visited = set()
for j in range(1, B+1):
calc = (j**2)%B
if calc not in visited:
visited.add(calc)
if calc <= R_remainder and R_remainder-calc < diff:
diff = R_remainder-calc
num = j
elif calc in visited:
break
X.append(num)
R_remainder -= (num**2)%B
if R_remainder == 0:
for i in range(3):
X.append(B)
print('YES')
print(*X)
else:
for x4 in range(0, R_remainder+1):
for x5 in range(0, R_remainder+1):
for x6 in range(0, R_remainder+1):
if (x4**2 + x5**2 + x6**2)%B == R_remainder:
if x4 == 0:
x4 = B
if x5 == 0:
x5 = B
if x6 == 0:
x6 = B
X.extend([x4, x5, x6])
print('YES')
print(*X)
exit()
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0