#include using namespace std; using ll = long long; int main(){ cin.tie(nullptr); ios_base::sync_with_stdio(false); ll N, M, A, ans=0; cin >> N >> M; set st; if (M % 2 == 1){ cout << 0 << endl; return 0; } for (int i=0; i> A; A %= M; st.insert(A); } for (auto x : st){ if (st.count((x+M/2)%M)) ans += N-2; } cout << ans/2 << endl; return 0; }