#include using namespace std; void fast_io() { ios::sync_with_stdio(false); std::cin.tie(nullptr); } int main() { fast_io(); int n; long long m; cin >> n >> m; if (m <= 2) { if (n == 1) { cout << 2 << endl; } else { cout << 0 << endl; } return 0; } if (n == 1) { cout << (long long)(m - 1) * (m - 2) / 2 + 3 << endl; return 0; } vector f{0, 1, 1}; while (true) { f.push_back((f[f.size() - 1] + f[f.size() - 2]) % n); if (f[f.size() - 1] == 1 && f[f.size() - 2] == 0) { break; } } f.pop_back(); f.pop_back(); int per = f.size(); auto get = [&](long long i) { return f[i % per]; }; long long ans = 0; if (get(m + 2) == get(m + 1)) { ans++; } if (get(m + 1) == get(m)) { ans++; } if (get(m) == get(m - 1)) { ans++; } vector cnt(n); for (int i = 0; i < per; i++) { cnt[get(i)] += max(0LL, (m - i + per) / per); if (i < 2) { cnt[get(i)]--; } } for (int i = 0; i < n; i++) { ans += cnt[i] * (cnt[i] - 1) / 2; } cout << ans << endl; }