結果

問題 No.648  お や す み 
ユーザー kamome
提出日時 2020-04-15 23:43:29
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 39 ms / 2,000 ms
コード長 430 bytes
コンパイル時間 391 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,264 KB
最終ジャッジ日時 2024-10-01 19:08:28
合計ジャッジ時間 4,955 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 84
権限があれば一括ダウンロードができます

ソースコード

diff #

from decimal import *
i=Decimal(input())
x=1

def df(n):
    return 2*n

def f(n):
    return Decimal(0.5)*(n**2)+Decimal(0.5)*n-i
def s(n):
    return Decimal(0.5)*(n**2)+Decimal(0.5)*n
op=1
while True:
    prev=x
    x=x-(f(x)/df(x)) # ニュートン法
    if abs(prev - x) < 0.01:
        break
x=Decimal(int(x-3))
for j in range(6):
    x=x+1
    if s(x)==i:
        print("YES")
        print(x)
        exit()
print("NO")
0