A1370 | [COCI-2017_2018-contest6]#4 Kotrljanje
来源COCI
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
Vla-tko, Vla-tko, Vla-tko!
Nobody comes to Vlatko’s office hours anymore. Angered, enraged and disgruntled, Vlatko’s revenge is a convenient task for COCI:
You are given an infinite arithmetic sequence A(n) = Cn + D, defined for all natural numbers n. We want find a sequence of M distinct natural numbers n1, n2, ..., nM less than or equal to 10^15 such that the corresponding members of sequence A(n1), A(n2), ..., A(nM) all have the same sum of digits in base B.
Please note: Every positive integer N can be written in base B as follows: create the unique string xkxk-
1...x1x0, where 0 ≤ xi < B for each i, and the equation xkBk + xk-1Bk-1 + ... + x1B + x0 =N is satisfied. The sum of digits is given with xk + ... + x
0.
Nobody comes to Vlatko’s office hours anymore. Angered, enraged and disgruntled, Vlatko’s revenge is a convenient task for COCI:
You are given an infinite arithmetic sequence A(n) = Cn + D, defined for all natural numbers n. We want find a sequence of M distinct natural numbers n1, n2, ..., nM less than or equal to 10^15 such that the corresponding members of sequence A(n1), A(n2), ..., A(nM) all have the same sum of digits in base B.
Please note: Every positive integer N can be written in base B as follows: create the unique string xkxk-
1...x1x0, where 0 ≤ xi < B for each i, and the equation xkBk + xk-1Bk-1 + ... + x1B + x0 =N is satisfied. The sum of digits is given with xk + ... + x
0.
输入格式
The first line of input contains four integers C, D, B and M (1 ≤ C, D ≤ 10000, 2 ≤ B ≤ 5000, 1 ≤ M ≤ 250000).
输出格式
The first and only line of output must contain the required numbers, separated by spaces, in an arbitrary order.
Please note: you must output the numbers ni, not numbers A(ni). All numbers in the output should be less than or equal to 10^1
5.
The input data will be such that a solution that meets the given conditions exists.
Please note: you must output the numbers ni, not numbers A(ni). All numbers in the output should be less than or equal to 10^1
5.
The input data will be such that a solution that meets the given conditions exists.
输入输出样例
输入 #1
5 3 2 2
输出 #1
2 5
输入 #2
2 1 10 3
输出 #2
2 20 200
Clarification of the test cases:
In the first test case, one of the possible sequences is the sequence in the output. The corresponding
members of the arithmetic sequence are 5 * 2 + 3 = 13 and 5 * 5 + 3 = 28. The format of number 13 in
base 2 is 1101, whereas the format of number 28 in base 2 is 11100. The sum of digits in both
formats is equal to 3.
In the second test case, the corresponding members of the sequence are 2 * 2 + 1 = 5, 2 * 20 + 1 =
41, and 2 * 200 + 1 = 401. Each of the numbers’ digits, written in base 10, sum up to 5.
In the first test case, one of the possible sequences is the sequence in the output. The corresponding
members of the arithmetic sequence are 5 * 2 + 3 = 13 and 5 * 5 + 3 = 28. The format of number 13 in
base 2 is 1101, whereas the format of number 28 in base 2 is 11100. The sum of digits in both
formats is equal to 3.
In the second test case, the corresponding members of the sequence are 2 * 2 + 1 = 5, 2 * 20 + 1 =
41, and 2 * 200 + 1 = 401. Each of the numbers’ digits, written in base 10, sum up to 5.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted