A1268 | [COCI-2012_2013-contest4]#4 OREHNJACA
来源COCI
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
In the faraway city of Xanadu, a flu epidemic has broken out, caused by a strain known as hairy flu.
There are M people living in the city, each resident having a unique personal ID number from the range of 0 to M – 1, inclusive. Infection with this strain lasts exactly one day, and a person can catch it multiple times per season (since it mutates too quickly for lasting immunity).
On the first day of the epidemic, the flu was brought from another faraway country by a group of residents nicknamed “init-patients”, whose ID numbers are known. The flu's spread is based on them.
Each following day, a resident with ID number p will catch the flu iff there exists a resident with ID a who was infected the previous day, as well as an init-patient with ID b, such that:
(a * b) mod M = p.
The numbers a and b need not be distinct. For example, consider a case where there are 101 people in the town, and the init-patients are 5 and 5
0. On the first day, the init-patients are infected by definition.
On the second day, the residents infected are 25, 48 (250 mod 101), and 76 (2500 mod 101). On the third day, one of the infected patients is 77, since (48 * 50) mod 101 = 7
7.
Who will catch the flu on the K-th day?
There are M people living in the city, each resident having a unique personal ID number from the range of 0 to M – 1, inclusive. Infection with this strain lasts exactly one day, and a person can catch it multiple times per season (since it mutates too quickly for lasting immunity).
On the first day of the epidemic, the flu was brought from another faraway country by a group of residents nicknamed “init-patients”, whose ID numbers are known. The flu's spread is based on them.
Each following day, a resident with ID number p will catch the flu iff there exists a resident with ID a who was infected the previous day, as well as an init-patient with ID b, such that:
(a * b) mod M = p.
The numbers a and b need not be distinct. For example, consider a case where there are 101 people in the town, and the init-patients are 5 and 5
0. On the first day, the init-patients are infected by definition.
On the second day, the residents infected are 25, 48 (250 mod 101), and 76 (2500 mod 101). On the third day, one of the infected patients is 77, since (48 * 50) mod 101 = 7
7.
Who will catch the flu on the K-th day?
输入格式
The first line of input contains three positive integers, K, M, and N (1 ≤ K ≤ 1018, 3 ≤ M ≤ 1500, N <
M).
The second line of input contains N space-separated nonnegative integers, the personal ID numbers of residents who were infected on the first day (the init-patients). These numbers are unique, increasing,
and do not exceed M -
1.
M).
The second line of input contains N space-separated nonnegative integers, the personal ID numbers of residents who were infected on the first day (the init-patients). These numbers are unique, increasing,
and do not exceed M -
1.
输出格式
The first and only line of output must contain the personal ID numbers of residents infected with flu on the K-th day, given space-separated and in increasing order.
输入输出样例
输入 #1
1 100 3 1 2 3
输出 #1
1 2 3
输入 #2
2 100 3 1 2 3
输出 #2
1 2 3 4 6 9
输入 #3
10 101 2 5 50
输出 #3
36 44 57 65
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted