List of Powers
Time limit3.5sMemory limit1024 MB
Given a prime p and a base a, list every integer in [l, r] that equals a^k mod p for some non-negative k, in ascending order.
- Level
Medium6 of 10
- Topics
- Math, Number theory, Implementation
- Solved
- No attempts yet
Problem
Let be a prime number and an integer such that . Find all integers from to inclusive that can be written as for some non-negative integer . The number of such integers is at most .
Input
The only line contains four integers , , , and , separated by spaces. The constraints are , is prime, and .
Output
Print all integers from to inclusive that can be written as for some non-negative integer , in ascending order. Separate consecutive integers by spaces. The input is guaranteed to have at most such integers.
Hint
Since is prime and , is not a multiple of , so is never . The values of repeat in a cycle as grows.