結果

問題 No.220 世界のなんとか2
ユーザー mobius_bkstmobius_bkst
提出日時 2015-05-31 13:08:52
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 944 bytes
コンパイル時間 6,177 ms
コンパイル使用メモリ 76,784 KB
実行使用メモリ 49,700 KB
最終ジャッジ日時 2023-09-20 17:57:52
合計ジャッジ時間 6,198 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
49,268 KB
testcase_01 AC 45 ms
49,528 KB
testcase_02 AC 45 ms
49,132 KB
testcase_03 AC 44 ms
49,180 KB
testcase_04 AC 45 ms
49,592 KB
testcase_05 AC 46 ms
49,296 KB
testcase_06 AC 46 ms
49,336 KB
testcase_07 AC 44 ms
49,588 KB
testcase_08 AC 46 ms
49,156 KB
testcase_09 AC 46 ms
49,312 KB
testcase_10 AC 46 ms
49,528 KB
testcase_11 AC 45 ms
49,156 KB
testcase_12 AC 46 ms
49,348 KB
testcase_13 AC 46 ms
49,700 KB
testcase_14 AC 46 ms
49,524 KB
testcase_15 AC 46 ms
49,428 KB
testcase_16 AC 47 ms
49,244 KB
testcase_17 AC 47 ms
49,244 KB
testcase_18 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class No220_2 {
    public static void main(String[] args) {
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(
                    System.in));
            int P = Integer.parseInt(br.readLine());

            // 10^n-1-(2/3)×9^n
            // なんかPがでかいと誤差死するので3で割るのは最後にする
            long p10 = pow(10, P) * 3;
            long p9 = 2 * pow(9, P);
            long ans = p10 - 3 - p9;
            System.out.println(ans / 3);
        } catch (Exception e) {
            System.err.println("Error:" + e.getMessage());
        }
    }

    static long pow(long a, long N) {

        long res = 1;
        while (N > 0) {
            if ((N & 1) != 0) {
                res = res * a;
            }
            a = a * a;
            N >>= 1;
        }
        return res;
    }
}
0