using i64 = longlong; using u64 = unsignedlonglong; using u32 = unsigned; using u128 = unsigned __int128;
constexprint mod = 1e9 + 7; structMatrix { vector<vector<i64>> a; Matrix() { a.assign(3, vector<i64>(3)); } Matrix operator*(const Matrix b) const { Matrix res; for (int i = 1; i <= 2; i++) { for (int j = 1; j <= 2; j++) { for (int k = 1; k <= 2; k++) { res.a[i][j] = (res.a[i][j] + a[i][k] * b.a[k][j]) % mod; } } } return res; } voidinita(){ a[1][1] = a[1][2] = 1; } voidinitb(){ a[1][1] = a[2][1] = a[1][2] = 1; } };
Matrix qpow(Matrix a, i64 b){ Matrix res; for (int i = 1; i <= 2; i++) { res.a[i][i] = 1; } while (b) { if (b % 2 == 1) { res = res * a; } a = a * a; b /= 2; } return res; }
voidsolve(){ i64 n; cin >> n; if (n <= 2) { cout << 1 << "\n"; return; } Matrix a, b; a.inita(), b.initb(); a = a * qpow(b, n - 2); cout << a.a[1][1] << "\n"; }
signedmain(){ ios::sync_with_stdio(false); cin.tie(0); int t = 1; // cin >> t; while (t--) { solve(); } return0; }
#include<bits/stdc++.h> usingnamespace std; #define int long long
int dp[10][2]; int n, m, sz; int c[10]; intdfs(int pos, bool sta, bool limit){ int ans = 0; if (pos == sz + 1) { return1; } if (!limit && dp[pos][sta] != -1) { return dp[pos][sta]; } int up = limit ? c[pos] : 9; for (int i = 0; i <= up; i++) { if (sta && i == 2) { continue; } if (i == 4) { continue; } ans += dfs(pos + 1, i == 6, limit && i == up); } if (!limit) { dp[pos][sta] = ans; } return ans; }
voidsolve(){ while (true) { cin >> n >> m; if (n == 0 && m == 0) { break; } for (int i = 0; i < 8; i++) { for (int j = 0; j < 2; j++) { dp[i][j] = -1; } } string s = to_string(m); sz = s.size(); s = " " + s; for (int i = 1; i <= sz; i++) { c[i] = s[i] - '0'; } int ans = dfs(1, false, true); for (int i = 0; i < 8; i++) { for (int j = 0; j < 2; j++) { dp[i][j] = -1; } } s = to_string(n - 1); sz = s.size(); s = " " + s; for (int i = 1; i <= sz; i++) { c[i] = s[i] - '0'; } ans -= dfs(1, false, true); cout << ans << "\n"; } }
signedmain(){ ios::sync_with_stdio(false); cin.tie(0); int t = 1; // cin >> t; while (t--) { solve(); } return0; }