List of Powers
면접 대비시간 제한3.5초메모리 제한1024 MB
소수 p, 밑 a, 구간 [l, r]이 주어질 때 a^k mod p 값 중 구간에 들어가는 수를 오름차순으로 출력한다.
문제
Let be a prime number and an integer such that . Consider all integers from to inclusive which can be expressed as for some non-negative integer . Given that the number of such integers is at most , print these integers in ascending order.
입력
The only line contains four integers , , , and separated by spaces (, is prime, ).
출력
Print all integers from to inclusive which can be expressed as for some non-negative integer . The integers must be printed in ascending order. Separate consecutive integers by spaces. The input is guaranteed to be such that the correct answer contains at most numbers.
힌트
In the first example, we must find all integers from up to inclusive which can be expressed as for some integer . These are numbers , and . The number can not be expressed this way because does not divide evenly by for any integer . So, we must print the numbers , , and in ascending order.
In the second example, we must find all integers from up to inclusive which can be expressed as for some integer . Let us write down the first few such numbers: , , , , , . It can be proved that this sequence contains only numbers and . So, the result is an empty list.