結果

問題 No.2079 aaabbc
ユーザー Andrey GalyshAndrey Galysh
提出日時 2022-09-25 22:00:09
言語 Java
(openjdk 23)
結果
AC  
実行時間 142 ms / 2,000 ms
コード長 859 bytes
コンパイル時間 2,636 ms
コンパイル使用メモリ 75,076 KB
実行使用メモリ 43,200 KB
最終ジャッジ日時 2024-12-22 14:37:22
合計ジャッジ時間 5,164 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 11
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.util.stream.*;

public class Main {
    static Scanner scan;
    public static long M = 998_244_353l;
    public static long pow(long n, long p, long m) {
        if (p == 0) {
            return 1l;
        }
        if (n == 0) {
            return 0l;
        }
        int lp = 0; //log_2{p}
        long tp = p;
        while (tp > 0) {
            tp >>= 1;
            lp++;
        }
        long tn = n % m;
        tp = p;
        long res = 1;
        for (int i = 0; i < lp; i++) {
            if ((tp & 1) > 0) {
                res = (res*tn)%m;
            }
            tn = (tn*tn)%m;
            tp >>= 1;
        }
        return res;
    }
    public static void main(String []args) {
        scan = new Scanner(System.in);
        int n = scan.nextInt();
        System.out.println(pow(3l, n, M));
    }
}
0