結果

問題 No.793 うし数列 2
ユーザー tentententen
提出日時 2020-09-03 09:04:45
言語 Java21
(openjdk 21)
結果
AC  
実行時間 152 ms / 2,000 ms
コード長 974 bytes
コンパイル時間 4,246 ms
コンパイル使用メモリ 76,892 KB
実行使用メモリ 41,872 KB
最終ジャッジ日時 2024-05-02 08:00:09
合計ジャッジ時間 8,706 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 152 ms
41,804 KB
testcase_01 AC 139 ms
41,040 KB
testcase_02 AC 148 ms
41,348 KB
testcase_03 AC 145 ms
41,676 KB
testcase_04 AC 142 ms
41,308 KB
testcase_05 AC 140 ms
41,348 KB
testcase_06 AC 141 ms
41,576 KB
testcase_07 AC 146 ms
41,292 KB
testcase_08 AC 150 ms
41,448 KB
testcase_09 AC 147 ms
41,392 KB
testcase_10 AC 147 ms
41,708 KB
testcase_11 AC 145 ms
41,872 KB
testcase_12 AC 149 ms
41,316 KB
testcase_13 AC 151 ms
41,612 KB
testcase_14 AC 145 ms
41,396 KB
testcase_15 AC 144 ms
41,796 KB
testcase_16 AC 143 ms
41,340 KB
testcase_17 AC 144 ms
41,792 KB
testcase_18 AC 137 ms
41,048 KB
testcase_19 AC 138 ms
41,436 KB
testcase_20 AC 148 ms
41,316 KB
testcase_21 AC 148 ms
41,316 KB
testcase_22 AC 147 ms
41,216 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[] allThrees = new long[63];
    	allThrees[0] = 3;
    	for (int i = 1; i < 63; i++) {
    	    allThrees[i] = allThrees[i - 1] * (1 + pow(10, 1L << (i - 1))) % MOD;
    	}
    	long ans = 0;
    	int add = 0;
    	long x = n;
    	for (int i = 0; i < 63 && x > 0; i++) {
    	    if (x % 2 == 1) {
    	        ans *= pow(10, 1L << i);
    	        ans %= MOD;
    	        ans += allThrees[i];
    	        ans %= MOD;
    	        add += i + 1;
    	    }
    	    x /= 2;
    	}
    	ans += pow(10, n);
    	ans %= MOD;
    	System.out.println(ans);
	}
	
	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