#include using namespace std; using ll = long long; #define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++) #define all(p) (p).begin(),(p).end() int main(){ ll N, M; cin >> N >> M; if (M <= 2){ cout << (N == 1 ? 2 : 0) << "\n"; return 0; } ll ans = 0; int a = 0, b = 1; vector p(N); for (int i = 2; i <= M; i++){ a = (a + b); if (a >= N) a -= N; swap(a, b); ans += p[b]; p[b]++; } if (a == 0) ans++; if (b == 0) ans += 2; cout << ans << "\n"; }