Monic irreducible polynomials P64196


Statement
 

pdf   zip

Here, we consider polynomials in ๐”ฝp[x]\mathbb{F}_p[x], that is, polynomials on xx whose coefficients are elements of ๐”ฝp={0,1,2,โ€ฆ,pโˆ’1}\mathbb{F}_p=\{0, 1, 2, \ldots, p-1\}, where pp is a prime number.

A polynomial is monic if the coefficient of its term with largest degree is 11. A polynomial is irreducible if it cannot be written as the product of two polynomials of smaller degree. Your task is to count the number of monic, irreducible polynomials of ๐”ฝp[x]\mathbb{F}_p[x] of a given degree dd.

Too difficult? Do not despair! The problem is not so hard, once you know that, in ๐”ฝp[x]\mathbb{F}_p[x], every monic polynomial can be written in a unique way as a factor of monic, irreducible polynomials. For instance, in ๐”ฝ2[x]\mathbb{F}_2[x] there are 44 monic polynomials of degree 22 (in ๐”ฝ2[x]\mathbb{F}_2[x], all polynomials are monic), but only one of them is irreducible: x2=xโ‹…xx2+1=(x+1)โ‹…(x+1)x2+x=xโ‹…(x+1)x2+x+1=???x^2 = x\cdot x \qquad \enspace x^2+1 = (x+1)\cdot(x+1) \qquad \enspace x^2+x = x\cdot (x+1) \qquad \enspace x^2+x+1 = \enspace ???

In ๐”ฝ2[x]\mathbb{F}_2[x], there are 88 monic polynomials of degree 33, but only two of them are irreducible: x3=xโ‹…xโ‹…xx3+x2=xโ‹…xโ‹…(x+1)x3+1=(x+1)โ‹…(x2+x+1)x3+x2+1=???x3+x=xโ‹…(x+1)โ‹…(x+1)x3+x2+x=xโ‹…(x2+x+1)x3+x+1=???x3+x2+x+1=(x+1)โ‹…(x+1)โ‹…(x+1)\begin{align*} x^3 &= x\cdot x \cdot x \enspace & \enspace x^3 + x^2 &= x\cdot x\cdot (x+1) \\ x^3+1 &= (x+1)\cdot(x^2+x+1) \enspace & \enspace x^3+x^2+1 &= \enspace ??? \\ x^3 + x &= x\cdot (x+1)\cdot (x+1) \enspace & \enspace x^3 + x^2 + x &= x\cdot (x^2+x+1) \\ x^3+x+1 &= \enspace ??? \enspace & \enspace x^3+x^2+x+1 &= (x+1)\cdot(x+1)\cdot(x+1) \end{align*}

Input

Input consists of several cases, each with a prime number 2โ‰คpโ‰ค302 \le p \le 30 and an integer number 2โ‰คdโ‰ค302 \le d \le 30. Additionally, we have pd<109p^d < 10^9.

Output

For every case, print the number of monic, irreducible polynomials in ๐”ฝp[x]\mathbb{F}_p[x] of degree dd.

Public test cases
  • Input

    2 2
    2 3
    2 4
    2 30
    3 2
    3 3
    3 4
    3 19
    29 6
    

    Output

    1
    2
    3
    35790267
    3
    8
    18
    61171656
    99133020
    
  • Information
    Author
    Omer Giménez
    Language
    English
    Official solutions
    C++
    User solutions
    C++