結果
問題 |
No.793 うし数列 2
|
ユーザー |
![]() |
提出日時 | 2020-09-03 09:04:45 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 132 ms / 2,000 ms |
コード長 | 974 bytes |
コンパイル時間 | 2,147 ms |
コンパイル使用メモリ | 77,964 KB |
実行使用メモリ | 41,556 KB |
最終ジャッジ日時 | 2024-11-22 20:09:25 |
合計ジャッジ時間 | 6,183 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 21 |
ソースコード
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; } } }