結果

問題 No.2079 aaabbc
ユーザー Andrey GalyshAndrey Galysh
提出日時 2022-09-25 22:00:09
言語 Java21
(openjdk 21)
結果
AC  
実行時間 124 ms / 2,000 ms
コード長 859 bytes
コンパイル時間 2,123 ms
コンパイル使用メモリ 72,532 KB
実行使用メモリ 56,332 KB
最終ジャッジ日時 2023-08-24 02:12:56
合計ジャッジ時間 4,779 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
55,668 KB
testcase_01 AC 121 ms
55,836 KB
testcase_02 AC 120 ms
55,920 KB
testcase_03 AC 118 ms
56,244 KB
testcase_04 AC 119 ms
55,720 KB
testcase_05 AC 119 ms
55,652 KB
testcase_06 AC 116 ms
55,460 KB
testcase_07 AC 120 ms
55,648 KB
testcase_08 AC 120 ms
55,748 KB
testcase_09 AC 122 ms
55,740 KB
testcase_10 AC 123 ms
55,804 KB
testcase_11 AC 124 ms
55,780 KB
testcase_12 AC 119 ms
55,944 KB
testcase_13 AC 118 ms
55,736 KB
testcase_14 AC 118 ms
55,920 KB
testcase_15 AC 120 ms
56,332 KB
権限があれば一括ダウンロードができます

ソースコード

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