#line 1 "main.cpp" #include #include #include #include #include using namespace std; using lint = long long; const vector fs{6, 2, 5, 5, 4, 5, 6, 4, 7, 6}; int f(const string& s) { int ret = 0; for (auto c : s) { if (c == '-') { ++ret; } else { ret += fs[c - '0']; } } return ret; } void solve() { string p, n; cin >> p >> n; if (n.length() <= 2) { // n <= 99なので全探索 int m = stoi(n); while (m--) p = to_string(f(p)); cout << p << "\n"; } else { // n >= 100 // とりあえず100回遷移 for (int i = 0; i < 100; ++i) p = to_string(f(p)); int x = p.front() - '0'; // ループするまで遷移 vector xs{x}; x = fs[x]; while (x != xs.front()) { xs.push_back(x); x = fs[x]; } int len = xs.size(); // (n - 100) mod lenを求める int s = 0; for (auto c : n) { s = (s * 10 + c - '0') % len; } s = ((s - 100) % len + len) % len; cout << xs[s] << "\n"; } } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); solve(); return 0; }