#include #include #include using namespace std; #pragma warning(disable:4996) long long K, L, R, U, V; string Y; long long sums(long long P, long long Q) { if (P >= (1LL << Q))return (1LL << 62); if (P < 0)return -(1LL << 62); long long ret = 0, U = P; for (int i = 1; i <= Q; i++) { ret += ((U + 1) / 2) * to_string(i).size(); U -= (U + 1) / 2; } return ret; } long long modpow(long long a, long long b, long long m) { long long p = 1, q = a; for (int i = 0; i < 63; i++) { if ((b / (1LL << i)) % 2 == 1)p *= q; q *= q; p %= m; q %= m; } return p; } void search() { //左の境界を探索 long long L1 = -1, R1 = (1LL << K) + 1, M1; while (true) { M1 = (L1 + R1) / 2; long long Y1 = sums(M1 - 1, K), Y2 = sums(M1, K); if (Y1 < L && Y2 >= L) { U = M1; U++; if (Y2 - L >= 1) { long long I = M1, J = 1; while (I % 2 == 0) { I /= 2; J++; } Y += to_string(J).substr(to_string(J).size() - (Y2 - L), (Y2 - L)); } break; } if (Y2 < L)L1 = M1; if (Y1 >= L)R1 = M1; } //右の境界を探索 L1 = -1; R1 = (1LL << K) + 1; while (true) { M1 = (L1 + R1) / 2; long long Y1 = sums(M1, K), Y2 = sums(M1 + 1, K); if (Y1 <= R && Y2 > R) { V = M1; if (R - Y1 >= 1) { long long I = M1, J = 1; I++; while (I % 2 == 0) { I /= 2; J++; } Y += to_string(J).substr(0, (R - Y1)); } break; } if (Y2 <= R)L1 = M1; if (Y1 > R)R1 = M1; } } void solve(long long K, long long L, long long R) { if (R > sums((1LL << K) - 1, K)) { cout << "-1" << endl; return; } search(); //端数部分の和と積を求める long long wa = 0, seki = 1; for (int i = 0; i < Y.size(); i++) { long long G = (Y[i] - '0'); if (G == 0)G = 10; wa += G; seki *= G; } //区間の部分の積と和を求める U--; for (int i = 1; i <= K; i++) { long long U1 = (U + 1) / 2; long long U2 = (V + 1) / 2; string T = to_string(i); long long w1 = 0, w2 = 1; for (int j = 0; j < T.size(); j++) { long long G = (T[j] - '0'); if (G == 0)G = 10; w1 += G; w2 *= G; } //cout << U2 - U1 << ' ' << U << ' ' << V << endl; wa += w1*(U2 - U1); seki *= modpow(w2, U2 - U1, 1000000007); seki %= 1000000007; U -= U1; V -= U2; } //出力 cout << wa << ' ' << seki << endl; } int main() { for (int h = 1; h <= 2; h++) { for (int i = 1; i <= 50; i++) { // ------ end ------ // string TS = to_string(h); string ID = to_string(i); if (ID.size() == 1)ID = "0" + ID; FILE *in = freopen(("./subtask" + TS + "_" + ID + ".txt").c_str(), "r", stdin); cin >> K >> L >> R; L--; FILE *out = freopen(("./subtask" + TS + "_" + ID + ".txt").c_str(), "w", stdout); solve(K, L, R); } } for (int i = 1; i <= 4; i++) { // ------ end ------ // string ID = to_string(i); if (ID.size() == 1)ID = "0" + ID; FILE *in = freopen(("./sample_" + ID + ".txt").c_str(), "r", stdin); cin >> K >> L >> R; L--; FILE *out = freopen(("./sample_" + ID + ".txt").c_str(), "w", stdout); solve(K, L, R); } for (int i = 1; i <= 5; i++) { // ------ end ------ // string ID = to_string(i); if (ID.size() == 1)ID = "0" + ID; FILE *in = freopen(("./special_" + ID + ".txt").c_str(), "r", stdin); cin >> K >> L >> R; L--; FILE *out = freopen(("./special_" + ID + ".txt").c_str(), "w", stdout); solve(K, L, R); } return 0; }