結果

問題 No.793 うし数列 2
ユーザー htensaihtensai
提出日時 2020-06-10 15:16:51
言語 Java21
(openjdk 21)
結果
AC  
実行時間 129 ms / 2,000 ms
コード長 734 bytes
コンパイル時間 4,074 ms
コンパイル使用メモリ 71,524 KB
実行使用メモリ 56,288 KB
最終ジャッジ日時 2023-09-05 10:10:46
合計ジャッジ時間 8,370 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
55,880 KB
testcase_01 AC 125 ms
55,660 KB
testcase_02 AC 123 ms
55,892 KB
testcase_03 AC 125 ms
55,732 KB
testcase_04 AC 126 ms
55,892 KB
testcase_05 AC 125 ms
55,888 KB
testcase_06 AC 124 ms
56,240 KB
testcase_07 AC 123 ms
55,992 KB
testcase_08 AC 126 ms
55,832 KB
testcase_09 AC 127 ms
55,500 KB
testcase_10 AC 125 ms
55,616 KB
testcase_11 AC 125 ms
55,760 KB
testcase_12 AC 125 ms
55,936 KB
testcase_13 AC 125 ms
55,852 KB
testcase_14 AC 124 ms
55,976 KB
testcase_15 AC 125 ms
55,852 KB
testcase_16 AC 129 ms
55,888 KB
testcase_17 AC 126 ms
55,660 KB
testcase_18 AC 126 ms
55,776 KB
testcase_19 AC 124 ms
55,908 KB
testcase_20 AC 124 ms
56,288 KB
testcase_21 AC 124 ms
55,876 KB
testcase_22 AC 125 ms
55,600 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    static final int MOD = 1000000007;
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long ans = getThree(n) + pow(10, n);
		ans %= MOD;
		System.out.println(ans);
	}
	
	static long getThree(long x) {
	    if (x == 1) {
	        return 3;
	    } else if (x % 2 == 0) {
	        return getThree(x / 2) * (pow(10, x / 2) + 1) % MOD;
	    } else {
	        return (getThree(x - 1) + pow(10, x - 1) * 3) % 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;
	    }
	}
}
0