結果

問題 No.1680 Sum and Difference
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2021-09-17 22:01:24
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 579 bytes
コンパイル時間 279 ms
コンパイル使用メモリ 87,052 KB
実行使用メモリ 71,696 KB
最終ジャッジ日時 2023-09-12 07:33:30
合計ジャッジ時間 2,898 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,076 KB
testcase_01 AC 74 ms
71,308 KB
testcase_02 AC 76 ms
71,316 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 76 ms
71,248 KB
testcase_06 AC 76 ms
71,532 KB
testcase_07 AC 75 ms
71,232 KB
testcase_08 WA -
testcase_09 AC 75 ms
71,088 KB
testcase_10 AC 76 ms
71,252 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 74 ms
71,308 KB
testcase_14 AC 75 ms
71,436 KB
testcase_15 AC 76 ms
71,408 KB
testcase_16 AC 77 ms
71,372 KB
testcase_17 AC 79 ms
71,280 KB
testcase_18 WA -
testcase_19 AC 77 ms
71,572 KB
testcase_20 AC 77 ms
71,248 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(ans%mod)
0