#include using namespace std; using ll = long long; const ll mod = 998244353; const int iinf = 0x3fffffff; const ll inf = 0x1fffffffffffffff; using i128 = __int128; using pii = pair; using pll = pair; template ostream& operator<<(ostream &o, vector v) { for (int i = 0; i < v.size(); i++) { o << v[i] << " \n"[i+1==v.size()]; } return o; } void solve() { int n; ll m; cin >> n >> m; ll a = 0 % n; ll b = 1 % n; vector f{0}; while (true) { ll c = (a + b) % n; a = b; b = c; if (a == 0 % n && b == 1 % n) { break; } f.emplace_back(a); } int s = f.size(); ll ans = 0; if (f[m % s] % n == 0) { ans += 1; } if (f[(m + s - 1) % s] % n == 0) { ans += 1; } if (m >= 3 && (f[(m + s - 1) % s] + f[(m + s - 2) % s]) % n == 0) { ans += 1; } vector cnt(n); for (int i = 0; i < s; i++) { cnt[f[i]] += (m + 1 - i + s - 1) / s; } cnt[0]--; cnt[1 % n]--; for (int i = 0; i < n; i++) { ans += cnt[i] * (cnt[i] - 1) / 2; } cout << ans << endl; } int main() { cin.tie(0)->sync_with_stdio(false); solve(); }