CF703E.Mishka and Divisors

省选/NOI-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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?

在玩过她那漂亮的数组后,Mishka 决定学习一些数学知识。在学会了乘法、除法以及整除的概念之后,她现在对解决如下问题产生了兴趣。

给定一个整数 kk 和一个由 nn 个整数组成的数组 a1, a2, …, ana_1,\,a_2,\,\dots,\,a_n。你需要找出该数组的一个非空子序列,使得该子序列中所有元素的乘积能被 kk 整除,并且该子序列所含元素个数尽可能少。

形式化地说,你需要找出一组下标序列 1≤i1<i2<⋯<im≤n1\le i_1 < i_2 < \dots < i_m \le n,使得乘积

能被 kk 整除,且在所有满足该条件的子序列中,mm 取最小可能值。

若存在多个满足上述条件的子序列,则应在其中选择元素之和最小的一个。

Mishka 很快解决了这个问题。你也能做到吗?

输入格式

The first line of the input contains two integers n and k (1 ≤ n ≤ 1 000, 1 ≤ k ≤ 1012).

The second line of the input contains n integers _a_1, _a_2, ..., a__n (1 ≤ a__i ≤ 1012) — array elements.

输入的第一行包含两个整数 nn 和 kk(1 ≤ n ≤ 1 0001 \leq n \leq 1 000,1 ≤ k ≤ 10121 \leq k \leq 10^{12})。

输入的第二行包含 nn 个整数 a1, a2, ..., ana_1,\,a_2,\,...,\,a_n(1 ≤ ai ≤ 10121 \leq a_i \leq 10^{12})—— 数组元素。

输出格式

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.

第一行输出一个正整数 mm —— 所求序列的元素个数。

第二行输出 mm 个互不相同的整数 —— 所给数组中应被选入所求序列的元素的下标序列。

若存在多个满足条件的子序列(例如:元素个数最少的子序列,且在这些子序列中元素和也最小),则可任选其一输出。

若不存在满足条件的子序列,则仅在一行中输出 −1-1。

输入输出样例

  • 输入#1

    5 60
    2 4 6 5 2

    输出#1

    3
    4 3 1

输入解题思路,AI测评打分。不知道怎么写?

首页