結果

問題 No.1680 Sum and Difference
ユーザー mtrh
提出日時 2021-09-17 22:23:34
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 936 bytes
コンパイル時間 1,449 ms
コンパイル使用メモリ 166,484 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-29 21:00:12
合計ジャッジ時間 2,137 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll=long long;

int main(){
    ll A,B;
    cin>>A>>B;
    ll mod=1e9+7;
    if(A%2==0){
        ll ans=A+1;
        ans%=mod;
        ll t=(B/2)%mod;
        t*=(A%mod);
        t%=mod;
        t*=2;
        t%=mod;
        ans=(ans+t+10*mod)%mod;
        t=((B/2)%mod);
        t*=((A+1)%mod);
        t%=mod;
        t*=2;
        ans=(ans+t+10*mod)%mod;
        if(B%2==1){
            ans+=(2*(A%mod))%mod;
            ans=(ans+10*mod)%mod;
        }
        cout<<ans<<endl;
    }else{
        ll ans=A%mod;
        ll t=(B/2)%mod;
        t*=(A%mod);
        t%=mod;
        t*=2;
        t%=mod;
        ans=(ans+t+10*mod)%mod;
        t=(B/2)%mod;
        t*=((A+1)%mod);
        t%=mod;
        t*=2;
        ans=(ans+t+10*mod)%mod;
        if(B%2==1){
            ans+=2*((A+1)%mod);
            ans=(10*mod+ans)%mod;
        }
        cout<<ans<<endl;
    }
    return 0;
}
0