結果

問題 No.1680 Sum and Difference
ユーザー aaaaaaaaaa2230
提出日時 2021-09-17 22:05:12
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 39 ms / 1,000 ms
コード長 569 bytes
コンパイル時間 144 ms
コンパイル使用メモリ 82,040 KB
実行使用メモリ 53,596 KB
最終ジャッジ日時 2024-06-29 20:38:08
合計ジャッジ時間 1,700 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

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)%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