303641: CF703E. Mishka and Divisors

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Mishka and Divisors

题意翻译

## 题目描述 在玩完美丽的数列后, $Mishka$ 决定学习一些数学。现在她已经学习了乘法,除法和除数的定义,并对以下问题很感兴趣。 对于给定的正整数 $k$ 和长度为 $n$ 的数列 $a$ ,求出在所有元素乘积能被 $k$ 整除的情况下,所含元素最少的非空子集 换句话说,在数组 $a$ 中选出 $m$ 个数,使它们的乘积能被 $k$ 整除,并最小化 $m$ $(m≠0)$ 如果有多种符合要求的选择,取所选元素总和最小的一种 ## 输入格式 第一行两个正整数 $n$ 和 $k$ $(1≤n≤1000 , 1≤k≤10^{12})$ 第二行 $n$ 个正整数,即数列 $a$ $( 1≤a_{i}≤10^{12} ) $ ## 输出格式 第一行一个正整数 $m$ ,即所选非空子集的元素个数 第二行输出 $m$ 个正整数,即所选元素在数组 $a$ 中的下标(题目没说明顺序,但看样例是降序) 如果有多种选择( $m$ 最小且元素总和最小),输出任意一种 如果没有总乘积能被k整除的非空子集,仅输出 $-1$

题目描述

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}&lt;i_{2}&lt;...&lt;i_{m}<=n $ such that ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF703E/c2a59764950d80481f058298667066562c6293a4.png) 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.

输出格式


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.

输入输出样例

输入样例 #1

5 60
2 4 6 5 2

输出样例 #1

3
4 3 1 

Input

题意翻译

## 题目描述 在玩完美丽的数列后, $Mishka$ 决定学习一些数学。现在她已经学习了乘法,除法和除数的定义,并对以下问题很感兴趣。 对于给定的正整数 $k$ 和长度为 $n$ 的数列 $a$ ,求出在所有元素乘积能被 $k$ 整除的情况下,所含元素最少的非空子集 换句话说,在数组 $a$ 中选出 $m$ 个数,使它们的乘积能被 $k$ 整除,并最小化 $m$ $(m≠0)$ 如果有多种符合要求的选择,取所选元素总和最小的一种 ## 输入格式 第一行两个正整数 $n$ 和 $k$ $(1≤n≤1000 , 1≤k≤10^{12})$ 第二行 $n$ 个正整数,即数列 $a$ $( 1≤a_{i}≤10^{12} ) $ ## 输出格式 第一行一个正整数 $m$ ,即所选非空子集的元素个数 第二行输出 $m$ 个正整数,即所选元素在数组 $a$ 中的下标(题目没说明顺序,但看样例是降序) 如果有多种选择( $m$ 最小且元素总和最小),输出任意一种 如果没有总乘积能被k整除的非空子集,仅输出 $-1$

加入题单

算法标签: