A10516 | Mishka and Divisors
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
After playing with her beautiful array, Mishka decided to learn some math. After learning how to multiply, divide and what is divisibility, she is now interested in solving the following problem.
You are given integer $k$ and array $a_{1},a_{2},...,a_{n}$ of $n$ integers. You are to find non-empty subsequence of array elements such that the product of its elements is divisible by $k$ and it contains minimum possible number of elements.
Formally, you are to find a sequence of indices $1<=i_{1}<i_{2}<...<i_{m}<=n$ such that  is divisible by $k$ while $m$ is minimum possible among all such variants.
If there are more than one such subsequences, you should choose one among them, such that sum of its elements is minimum possible.
Mishka quickly solved this problem. Will you do so?
You are given integer $k$ and array $a_{1},a_{2},...,a_{n}$ of $n$ integers. You are to find non-empty subsequence of array elements such that the product of its elements is divisible by $k$ and it contains minimum possible number of elements.
Formally, you are to find a sequence of indices $1<=i_{1}<i_{2}<...<i_{m}<=n$ such that  is divisible by $k$ while $m$ is minimum possible among all such variants.
If there are more than one such subsequences, you should choose one among them, such that sum of its elements is minimum possible.
Mishka quickly solved this problem. Will you do so?
输入格式
The first line of the input contains two integers $n$ and $k$ ( $1<=n<=1000$ , $1<=k<=10^{12}$ ).
The second line of the input contains $n$ integers $a_{1},a_{2},...,a_{n}$ ( $1<=a_{i}<=10^{12}$ ) — array elements.
The second line of the input contains $n$ integers $a_{1},a_{2},...,a_{n}$ ( $1<=a_{i}<=10^{12}$ ) — array elements.
输出格式
Print single positive integer $m$ in the first line — the number of elements in desired sequence.
In the second line print $m$ distinct integers — the sequence of indices of given array elements, which should be taken into the desired sequence.
If there are more than one such subsequence (e.g. subsequence of minimum possible number of elements and with minimum possible sum of elements), you can print any of them.
If there are no such subsequences, print $-1$ in the only line.
In the second line print $m$ distinct integers — the sequence of indices of given array elements, which should be taken into the desired sequence.
If there are more than one such subsequence (e.g. subsequence of minimum possible number of elements and with minimum possible sum of elements), you can print any of them.
If there are no such subsequences, print $-1$ in the only line.
输入输出样例
输入 #1
5 60 2 4 6 5 2
输出 #1
3 4 3 1
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted