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

    ID: 7874 Type: RemoteJudge 1000ms 125MiB Tried: 23 Accepted: 13 Difficulty: 7 Uploaded By: Tags>搜索2007各省省选O2优化哈希HASH素数判断质数筛法天津

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

Problem 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