#P6091. Finding Primitive Roots

    ID: 19315 Type: Default 1000ms 256MiB

Finding Primitive Roots

Finding Primitive Roots

Given a positive integer \(n\) (which is guaranteed to have primitive roots) and an integer \(d\), find all the primitive roots modulo \(n\). Let the total number of primitive roots be \(c\) and denote them in increasing order as \(g_1, g_2, \ldots, g_c\). You are required to output \(g_d, g_{2d}, \ldots, g_{\lfloor c/d \rfloor \times d}\).

If you are not familiar with the definition, a positive integer \(g\) is called a primitive root modulo \(n\) if and only if \(1 \le g \le n-1\) and the order of \(g\) modulo \(n\) is \(\varphi(n)\), where \(\varphi(n)\) is Euler's totient function.

inputFormat

The input consists of a single line containing two integers \(n\) and \(d\) separated by a space.

  • \(n\): a positive integer that has primitive roots.
  • \(d\): a positive integer used to select every \(d\)-th primitive root in the sorted order.

outputFormat

Output the selected primitive roots separated by a single space. Specifically, if the primitive roots are \(g_1, g_2, \ldots, g_c\) in increasing order, output \(g_d, g_{2d}, \ldots, g_{\lfloor c/d \rfloor \times d}\).

sample

7 1
3 5