Invariant Polynomials

No attempts yetTime limit1sMemory limit512 MB

Problem

Consider a real polynomial P(x,y)P(x, y) in two variables. We call it invariant under the rotation by an angle α\alpha if

P(xcosαysinα,  xsinα+ycosα)=P(x,y)P(x\cos\alpha - y\sin\alpha,\; x\sin\alpha + y\cos\alpha) = P(x, y)

holds for all real xx and yy.

Consider the real vector space of all two-variable polynomials of degree at most dd that are invariant under the rotation by 2π/n2\pi/n. Compute the dimension MM of this vector space.

You may find the following remark useful: every polynomial of degree at most dd can be written uniquely as

P(x,y)=i,j0i+jdaijxiyjP(x, y) = \sum_{\substack{i, j \ge 0 \\ i + j \le d}} a_{ij}\, x^i y^j

for some real coefficients aija_{ij}.

Input

A single line with two positive integers dd and nn separated by one space. Both are less than 10001000.

Output

Output a single integer MM, the dimension of the vector space described above.