結果

問題 No.1680 Sum and Difference
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2021-09-17 22:02:12
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 597 bytes
コンパイル時間 320 ms
コンパイル使用メモリ 87,192 KB
実行使用メモリ 71,708 KB
最終ジャッジ日時 2023-09-12 07:35:55
合計ジャッジ時間 2,930 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,460 KB
testcase_01 AC 72 ms
71,360 KB
testcase_02 AC 72 ms
71,400 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 71 ms
71,676 KB
testcase_06 AC 72 ms
71,604 KB
testcase_07 AC 72 ms
71,472 KB
testcase_08 WA -
testcase_09 AC 72 ms
71,668 KB
testcase_10 AC 73 ms
71,504 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 74 ms
71,596 KB
testcase_17 AC 74 ms
71,388 KB
testcase_18 WA -
testcase_19 AC 75 ms
71,480 KB
testcase_20 AC 74 ms
71,708 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

a,b = map(int,input().split())
mod = 10**9+7
if a*b == 0:
    if a%2 or b%2:
        print((a+b)%mod)
    else:
        print((a+b+1)%mod)
    exit()
if a > b:
    a,b = b,a
if a%2 == b%2:
    l = (a-b)//2
    r = (b-a)//2
    ans = (r-l+1)*(2*a+1)%mod

    ans += (2*a)*((2*a+1)//2)%mod

else:
    if a%2:
        l = (a-b+1)//2
        r = (b-a-1)//2
        ans = (r-l+1)*(2*a+1)%mod
        ans += (2*a)*((2*a+1)//2)%mod
        print(-1)
    else:
        l = (a-b+1)//2
        r = (b-a-1)//2
        ans = (r-l+1)*(2*a+1)%mod
        ans += (2*a+2)*(a)%mod
        print(-1)

print(ans%mod)
0