結果

問題 No.1680 Sum and Difference
ユーザー aaaaaaaaaa2230
提出日時 2021-09-17 22:04:11
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 573 bytes
コンパイル時間 152 ms
コンパイル使用メモリ 82,264 KB
実行使用メモリ 54,208 KB
最終ジャッジ日時 2024-06-29 20:35:47
合計ジャッジ時間 1,465 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 12 WA * 6
権限があれば一括ダウンロードができます

ソースコード

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+1)*((2*a+1)//2)%mod
    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(ans%mod)
0