結果

問題 No.1680 Sum and Difference
ユーザー merlinmerlin
提出日時 2021-09-17 23:25:32
言語 Java21
(openjdk 21)
結果
AC  
実行時間 44 ms / 1,000 ms
コード長 756 bytes
コンパイル時間 2,158 ms
コンパイル使用メモリ 74,452 KB
実行使用メモリ 49,888 KB
最終ジャッジ日時 2023-09-12 09:32:23
合計ジャッジ時間 3,984 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
49,456 KB
testcase_01 AC 42 ms
49,256 KB
testcase_02 AC 44 ms
49,576 KB
testcase_03 AC 42 ms
49,512 KB
testcase_04 AC 43 ms
49,200 KB
testcase_05 AC 42 ms
49,376 KB
testcase_06 AC 43 ms
49,252 KB
testcase_07 AC 42 ms
49,200 KB
testcase_08 AC 43 ms
49,316 KB
testcase_09 AC 42 ms
49,268 KB
testcase_10 AC 43 ms
49,372 KB
testcase_11 AC 42 ms
49,888 KB
testcase_12 AC 43 ms
49,236 KB
testcase_13 AC 42 ms
49,200 KB
testcase_14 AC 42 ms
49,236 KB
testcase_15 AC 41 ms
49,416 KB
testcase_16 AC 42 ms
49,404 KB
testcase_17 AC 42 ms
49,304 KB
testcase_18 AC 42 ms
49,276 KB
testcase_19 AC 42 ms
49,200 KB
testcase_20 AC 42 ms
49,232 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

class Main
{
    public static void main(String args[])throws Exception
    {
        BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb=new StringBuilder();
        String s[]=bu.readLine().split(" ");
        long a=Long.parseLong(s[0]),b=Long.parseLong(s[1]);
        long M=(int)1e9+7,x=a%M,y=b%M,ans=(x*2+1)*(y*2+1)%M;
        if(a%2==b%2) ans=(ans+1)*power(2,M-2,M)%M;
        else ans=(ans-1)*power(2,M-2,M)%M;
        System.out.println(ans);
    }

    static long power(long a,long b,long M)
    {
        long res=1;
        while(b!=0)
        {
            if(b%2==1) res=res*a%M;
            b>>=1;
            a=a*a%M;
        }
        return res;
    }
}
0