//Sylwia Sapkowska #include <bits/stdc++.h> #include "dzilib.h" #pragma GCC optimize("O3", "unroll-loops") using namespace std; void __print(int x) {cerr << x;} void __print(long long x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << "'" << x << "'";} void __print(const char *x) {cerr << '"' << x << '"';} void __print(const string &x) {cerr << '"' << x << '"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #ifdef LOCAL #define debug(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define debug(x...) #endif #define int long long typedef pair<int, int> T; const int oo = 1e18, oo2 = 1e9+7, K = 30; const int mod = 998244353; int n; string s; vector<int>which; void solve(){ string t; vector<int>dig; for (int c = 0; c <= 17; c++){ auto d = Ask(c); dig.clear(); while (d){ dig.emplace_back(d%10); d/=10; } reverse(dig.begin(), dig.end()); for (auto dd: dig){ t += (char)(dd+'0'); } t += ','; } debug(t); int S = (int)t.size(); t += "$" + s; debug((int)t.size()); vector<int>pi((int)t.size()); for (int i = 1; i < (int)t.size(); i++) { int j = pi[i-1]; while (j > 0 && t[i] != t[j]) j = pi[j-1]; if (t[i] == t[j]) j++; pi[i] = j; if (pi[i] == S){ Answer(which[i-2*S]); return; } } assert(false); } int32_t main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int q = GetQ(); int c = GetC(); n = GetN(); n += 18; vector<int>p(n+1); debug(n); p[1] = 1; for (int i = 2; i<=n; i++){ if (!p[i]){ p[i] = i; for (int j = i*i; j<=n; j+=i){ if (!p[j]){ p[j] = i; } } } } auto divisors = [&](int x){ int cnt = 0, prev = -1; int ans = 1; while (x > 1){ if (p[x] != prev){ ans *= (cnt+1); cnt = 1; prev = p[x]; } else { cnt++; } x/=p[x]; } ans *= (cnt+1); return ans; }; vector<int>dig; for (int i = 1; i<=n; i++){ int d = divisors(i); dig.clear(); while (d){ dig.emplace_back(d%10); d/=10; } reverse(dig.begin(), dig.end()); for (auto dd: dig){ s += (char)(dd+'0'); which.emplace_back(i); } which.emplace_back(i); s += ','; } int t = GetT(); while (t--) solve(); return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | //Sylwia Sapkowska #include <bits/stdc++.h> #include "dzilib.h" #pragma GCC optimize("O3", "unroll-loops") using namespace std; void __print(int x) {cerr << x;} void __print(long long x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << "'" << x << "'";} void __print(const char *x) {cerr << '"' << x << '"';} void __print(const string &x) {cerr << '"' << x << '"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #ifdef LOCAL #define debug(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define debug(x...) #endif #define int long long typedef pair<int, int> T; const int oo = 1e18, oo2 = 1e9+7, K = 30; const int mod = 998244353; int n; string s; vector<int>which; void solve(){ string t; vector<int>dig; for (int c = 0; c <= 17; c++){ auto d = Ask(c); dig.clear(); while (d){ dig.emplace_back(d%10); d/=10; } reverse(dig.begin(), dig.end()); for (auto dd: dig){ t += (char)(dd+'0'); } t += ','; } debug(t); int S = (int)t.size(); t += "$" + s; debug((int)t.size()); vector<int>pi((int)t.size()); for (int i = 1; i < (int)t.size(); i++) { int j = pi[i-1]; while (j > 0 && t[i] != t[j]) j = pi[j-1]; if (t[i] == t[j]) j++; pi[i] = j; if (pi[i] == S){ Answer(which[i-2*S]); return; } } assert(false); } int32_t main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int q = GetQ(); int c = GetC(); n = GetN(); n += 18; vector<int>p(n+1); debug(n); p[1] = 1; for (int i = 2; i<=n; i++){ if (!p[i]){ p[i] = i; for (int j = i*i; j<=n; j+=i){ if (!p[j]){ p[j] = i; } } } } auto divisors = [&](int x){ int cnt = 0, prev = -1; int ans = 1; while (x > 1){ if (p[x] != prev){ ans *= (cnt+1); cnt = 1; prev = p[x]; } else { cnt++; } x/=p[x]; } ans *= (cnt+1); return ans; }; vector<int>dig; for (int i = 1; i<=n; i++){ int d = divisors(i); dig.clear(); while (d){ dig.emplace_back(d%10); d/=10; } reverse(dig.begin(), dig.end()); for (auto dd: dig){ s += (char)(dd+'0'); which.emplace_back(i); } which.emplace_back(i); s += ','; } int t = GetT(); while (t--) solve(); return 0; } |