結果

問題 No.613 Solitude by the window
ユーザー 夕叢霧香(ゆうむらきりか)夕叢霧香(ゆうむらきりか)
提出日時 2017-11-22 01:40:38
言語 Java21
(openjdk 21)
結果
AC  
実行時間 124 ms / 2,000 ms
コード長 1,198 bytes
コンパイル時間 2,083 ms
コンパイル使用メモリ 73,896 KB
実行使用メモリ 56,620 KB
最終ジャッジ日時 2023-08-20 23:14:09
合計ジャッジ時間 6,467 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
56,100 KB
testcase_01 AC 120 ms
56,620 KB
testcase_02 AC 119 ms
55,804 KB
testcase_03 AC 121 ms
56,020 KB
testcase_04 AC 119 ms
54,216 KB
testcase_05 AC 119 ms
56,108 KB
testcase_06 AC 124 ms
56,004 KB
testcase_07 AC 119 ms
56,048 KB
testcase_08 AC 121 ms
56,208 KB
testcase_09 AC 121 ms
55,860 KB
testcase_10 AC 120 ms
56,096 KB
testcase_11 AC 122 ms
56,432 KB
testcase_12 AC 123 ms
56,268 KB
testcase_13 AC 121 ms
55,796 KB
testcase_14 AC 122 ms
55,492 KB
testcase_15 AC 123 ms
56,404 KB
testcase_16 AC 120 ms
56,172 KB
testcase_17 AC 123 ms
55,956 KB
testcase_18 AC 123 ms
55,496 KB
testcase_19 AC 119 ms
55,812 KB
testcase_20 AC 120 ms
56,140 KB
testcase_21 AC 123 ms
56,196 KB
testcase_22 AC 120 ms
55,748 KB
testcase_23 AC 121 ms
55,804 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

class Main {
    static void myAssert(boolean e){
        if(!e)throw new RuntimeException("assertion sippai");
    }
    static boolean isPrime(long x){
        if(x<=1)return false;
        for(long i=2;i*i<=x;++i)if(x%i==0)return false;
        return true;
    }
    static long powerMod(long x, long exponent,long m) {
	long prod = 1;
	for (int i = 63; i >= 0; --i) {
	    prod = (prod * prod) % m;
	    if ((exponent & 1L << i) != 0) {
		prod = (prod * x) % m;
	    }
	}
	return prod;
    }
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        long n=scan.nextLong();
        long m=scan.nextLong();
        myAssert(n>=1);
        myAssert(n<=1000000000000000000L);
        myAssert(m>=2);
        myAssert(m<=1100000000);
        myAssert(isPrime(m));
        long p=m==2||m%12==1||m%12==11?m-1:m+1;
        long e=powerMod(2,n,p);
        long x=1,y=0;
        for(int i=31;i>=0;--i){
            long z=(x*x+3*y*y)%m,w=2*x*y%m;
            x=z;y=w;
            if((e&1L<<i)!=0){
                z=(2*x+3*y)%m;w=(x+2*y)%m;
                x=z;y=w;
            }
        }
        System.out.println((2*x+m-2)%m);
    }
}
0