Epidemic Flu
Time limit1sMemory limit128 MB
Find the set of people infected on day K using repeated multiplication modulo M against the day one infected set.
- Level
Hard8 of 10
- Topics
- Number theory, Math, Graph, Brute force
- Solved
- No attempts yet
Problem
An epidemic flu has started spreading through the village where Sang-geun lives. The village has people, numbered to . The flu lasts exactly one day, so a single person can catch it several times (on different days).
The flu was brought in by people who had visited another village and come back. Their numbers are all known, and on the first day exactly these people have the flu.
From the second day on, the flu spreads each day by the following rule: for every person who had the flu on the immediately preceding day and every person who had it on the first day, the person numbered catches the flu. Here and may be equal.
For example, suppose the village has people and the people infected on the first day are and . On the second day the infected people are , (), and (). One of the people infected on the third day is ().
Write a program that finds everyone who has the flu on day .
Input
The first line contains three integers , , and (, , ); is the number of people infected on the first day.
The second line contains the numbers of the people infected on the first day, separated by spaces.
Output
On one line, print the numbers of the people who have the flu on day , in ascending order, separated by spaces.