#P3846. 【模板】BSGS / [TJOI2007] 可爱的质数

    ID: 2762 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>搜索2007各省省选O2优化哈希,HASH素数判断,质数,筛法天津

【模板】BSGS / [TJOI2007] 可爱的质数

Description

Given a prime pp, an integer bb, and an integer nn, compute the smallest non-negative integer ll such that bln(modp)b^l \equiv n \pmod p.

Input Format

A single line contains 33 integers, representing p,b,np, b, n in order.

Output Format

A single line. If there exists an ll satisfying the requirement, output the smallest ll; otherwise output no solution.

5 2 3

3

Hint

Constraints

  • For all testdata, it is guaranteed that 2b<p<2312 \le b < p < 2^{31}, 1n<p1 \le n < p.

Translated by ChatGPT 5