結果
問題 |
No.1580 I like Logarithm!
|
ユーザー |
|
提出日時 | 2021-07-04 11:25:58 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 69 ms / 2,000 ms |
コード長 | 906 bytes |
コンパイル時間 | 748 ms |
コンパイル使用メモリ | 94,468 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-01 00:50:38 |
合計ジャッジ時間 | 4,048 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 6 |
other | AC * 39 |
ソースコード
#include <iostream> #include <string> #include <algorithm> #include <vector> #include <iomanip> #include <cmath> #include <stdio.h> #include <queue> #include <deque> #include <cstdio> #include <set> #include <map> #include <bitset> #include <stack> #include <cctype> using namespace std; long long mod = 1000000007; long long m_pow(long long x, long long y) { long long ans = 1; while (y > 0) { if ((y & 1) == 1) { ans = ans * x % mod; } x = x * x % mod; y >>= 1; } return ans; } int main() { long long a; string b; cin >> a >> b; long long ans = 0, num = 0, a1 = 1, n = b.size(); for (int i = n - 1; i >= 0; i--) { num += a1 * (b[i] - '0'); num %= mod; a1 *= a; a1 %= mod; } for (long long i = 0; i < n - 1; i++) { ans += i * (m_pow(a, i + 1) - m_pow(a, i)); ans %= mod; } ans += (n - 1) * (num - m_pow(a, n - 1) + 1); ans %= mod; cout << (ans + mod) % mod << endl; }