結果
問題 | No.493 とても長い数列と文字列(Long Long Sequence and a String) |
ユーザー |
![]() |
提出日時 | 2017-03-10 21:40:55 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 800 ms |
コード長 | 1,399 bytes |
コンパイル時間 | 706 ms |
コンパイル使用メモリ | 73,432 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-06-24 07:56:13 |
合計ジャッジ時間 | 3,413 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 115 |
ソースコード
#include <string>#include <vector>#include <iostream>#include <algorithm>using namespace std;const int mod = 1000000007;typedef long long ll;ll calc(ll x) {ll ret = 0;for (int i = 0; i < 60; i++) {ll cnt = (x >> i) - (x >> (i + 1));int d = to_string((i + 1) * (i + 1)).size();ret += d * cnt;}return ret;}vector<ll> solve(ll x) {ll l = 0, r = 1LL << 60;while (r - l > 1) {ll m = (l + r) >> 1;if (calc(m) <= x) l = m;else r = m;}vector<ll> v(10);for (int i = 0; i < 60; i++) {ll c = (l >> i) - (l >> (i + 1));int b = (i + 1) * (i + 1);while (b > 0) {v[b % 10] += c;b /= 10;}}ll pos = calc(l);int c = 1; l++;while (!(l & 1)) l >>= 1, c++;string t = to_string(c * c);for (int i = 0; i < x - pos; i++) v[t[i] - 48]++;return v;}int modpow(int a, ll b) {ll ret = 1;while (b) {if (b & 1) ret = 1LL * ret * a % mod;a = 1LL * a * a % mod;b >>= 1;}return ret;}int z[] = { 10, 1, 2, 3, 4, 5, 6, 7, 8, 9 };ll K, L, R;int main() {cin >> K >> L >> R; L--; K = min(K, 61LL);ll s = (1LL << K) - 1;if (R > calc(s)) cout << -1 << endl;else {vector<ll> r1 = solve(R), r2 = solve(L);long long sum = 0; int prod = 1;for (int i = 0; i < 10; i++) {sum += 1LL * z[i] * (r1[i] - r2[i]);prod = 1LL * prod * modpow(z[i], r1[i] - r2[i]) % mod;}cout << sum << ' ' << prod << endl;}return 0;}