/* -*- coding: utf-8 -*- * * 493.cc: No.493 とても長い数列と文字列(Long Long Sequence and a String) - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const int MAX_N = 100; typedef long long ll; const ll MAX_R = 1000000000000000000LL; const ll MOD = 1000000007; /* typedef */ /* global variables */ ll lfs[MAX_N], sums[MAX_N], muls[MAX_N]; int lds[MAX_N], ds[MAX_N][5];; /* subroutines */ ll sum_range(int k, ll l, ll r) { ll &lfk = lfs[k]; int &ldk = lds[k]; if (k <= 0 || r <= 0 || lfk <= l) return 0; if (l <= 0 && lfk <= r) return sums[k]; int off = lfs[k - 1] + ldk; ll sum = sum_range(k - 1, l, r) + sum_range(k - 1, l - off, r - off); ll i0 = max(l - lfs[k - 1], 0LL), i1 = min(r - lfs[k - 1], (ll)ldk); if (i0 < ldk && 0 < i1) for (int i = i0; i < i1; i++) sum += ds[k][i]; return sum; } ll mul_range(int k, ll l, ll r) { ll &lfk = lfs[k]; int &ldk = lds[k]; if (k <= 0 || r <= 0 || lfk <= l) return 1; if (l <= 0 && lfk <= r) return muls[k]; int off = lfs[k - 1] + ldk; ll mul = (mul_range(k - 1, l, r) * mul_range(k - 1, l - off, r - off)) % MOD; ll i0 = max(l - lfs[k - 1], 0LL), i1 = min(r - lfs[k - 1], (ll)ldk); if (i0 < ldk && 0 < i1) for (int i = i0; i < i1; i++) mul = (mul * ds[k][i]) % MOD; return mul; } /* main */ int main() { lfs[0] = 0; lds[0] = 0; sums[0] = 0; muls[0] = 1; int n; for (n = 1;; n++) { sums[n] = sums[n - 1] * 2; muls[n] = (muls[n - 1] * muls[n - 1]) % MOD; int n2 = n * n, l = 0; for (; n2 > 0; l++, n2 /= 10) { int d = n2 % 10; if (d == 0) d = 10; sums[n] += d; muls[n] = (muls[n] * d) % MOD; ds[n][l] = d; } lfs[n] = lfs[n - 1] * 2 + l; lds[n] = l; //printf("lfs[%d]=%lld (%d^2=%d(%d))", n, lfs[n], n, n * n, l); //printf(" sum=%lld, mul=%lld\n", sums[n], muls[n]); if (lfs[n] > MAX_R) break; } int k; ll l, r; cin >> k >> l >> r; l--; if (k > n) k = n; if (lfs[k] < r) { puts("-1"); return 0; } ll s = sum_range(k, l, r); ll m = mul_range(k, l, r); printf("%lld %lld\n", s, m); return 0; }