結果

問題 No.793 うし数列 2
ユーザー htensai
提出日時 2020-06-10 15:16:51
言語 Java
(openjdk 23)
結果
AC  
実行時間 152 ms / 2,000 ms
コード長 734 bytes
コンパイル時間 2,282 ms
コンパイル使用メモリ 74,168 KB
実行使用メモリ 41,432 KB
最終ジャッジ日時 2024-06-23 05:59:25
合計ジャッジ時間 6,716 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

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