結果

問題 No.793 うし数列 2
ユーザー tentententen
提出日時 2024-02-05 17:46:07
言語 Java21
(openjdk 21)
結果
AC  
実行時間 54 ms / 2,000 ms
コード長 1,760 bytes
コンパイル時間 2,450 ms
コンパイル使用メモリ 78,176 KB
実行使用メモリ 54,008 KB
最終ジャッジ日時 2024-02-05 17:46:13
合計ジャッジ時間 4,681 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
53,984 KB
testcase_01 AC 53 ms
53,984 KB
testcase_02 AC 53 ms
53,980 KB
testcase_03 AC 53 ms
53,996 KB
testcase_04 AC 53 ms
53,996 KB
testcase_05 AC 53 ms
53,988 KB
testcase_06 AC 54 ms
53,992 KB
testcase_07 AC 52 ms
53,984 KB
testcase_08 AC 52 ms
53,988 KB
testcase_09 AC 52 ms
53,988 KB
testcase_10 AC 53 ms
53,976 KB
testcase_11 AC 52 ms
53,988 KB
testcase_12 AC 52 ms
53,988 KB
testcase_13 AC 53 ms
53,976 KB
testcase_14 AC 52 ms
53,992 KB
testcase_15 AC 53 ms
53,984 KB
testcase_16 AC 53 ms
53,984 KB
testcase_17 AC 52 ms
53,992 KB
testcase_18 AC 52 ms
53,976 KB
testcase_19 AC 53 ms
54,008 KB
testcase_20 AC 53 ms
53,984 KB
testcase_21 AC 52 ms
53,976 KB
testcase_22 AC 52 ms
53,976 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.function.*;
import java.util.stream.*;

public class Main {
    static final int MOD = 1000000007;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        long n = sc.nextLong();
        System.out.println((pow(10, n) + length(3, n)) % MOD);
    }
    
    static long pow(long x, long p) {
        if (p == 0) {
            return 1;
        } else if (p % 2 == 0) {
            return pow(x * x % MOD, p / 2);
        } else {
            return pow(x, p - 1) * x % MOD;
        }
    }
    
    static long length(int x, long p) {
        if (p == 1) {
            return x;
        } else if (p % 2 == 0) {
            long tmp = length(x, p / 2);
            return (tmp * pow(10, p / 2) % MOD + tmp) % MOD;
        } else {
            return (length(x, p - 1) * 10 + x) % MOD;
        }
    }
}
class Scanner {
    BufferedReader br;
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() {
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
        } catch (Exception e) {
            
        }
    }
    
    public int nextInt() {
        return Integer.parseInt(next());
    }
    
    public long nextLong() {
        return Long.parseLong(next());
    }
    
    public double nextDouble() {
        return Double.parseDouble(next());
    }
    
    public String next() {
        try {
            while (!st.hasMoreTokens()) {
                st = new StringTokenizer(br.readLine());
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            return st.nextToken();
        }
    }
    
}
0