Untitled
Problem Descriptionthere is an integer $a $ and $n $ integers $b _1, \ldots, b_n$. After selecting some numbers from $b _1, \ldots, b_n$ in any order, say $c _1, \ldots, c_r$, we want to make sure that $a \ MoD \ c_1 \ mod \ c_2 \ mod \ldots \ mod \ c_r = 0$ (i.e., $a $ would become the remainder divided by $c _i$ each time, and a t the end, we want $a $ to become $0$). Please determine the minimum value of $r $. If The goal cannot be achieved, print $-1$ instead.
Inputthe first line contains one integer $T \leq 5$, which represents the number of testcases.
For each testcase, there is and both lines:
1. The first line contains integers $n $ and $a $ ($ \leq n \leq, 1 \leq a \leq 10^6$).
2. The second line contains $n $ integers $b _1, \ldots, b_n$ ($\forall 1\leq i \leq N, 1 \leq b_i \leq 10^6$).
Outputprint $T $ Answers in $T $ lines.
Sample Input22 9 2 7 2 9 6 7
Sample output2-1 Topic Link: http://acm.hdu.edu.cn/showproblem.php?pid=5339
1#include <cstdio>2#include <algorithm>3 using namespacestd;4 5 intAns,m,n;6 intb[ +];7 8 BOOLcmpintAintb)9 {Ten returnA>b; One } A - voidDfsintTotalintCurintnum) - { the if(total==0) - { -ans=min (ans,num); - return; + } - if(cur==m) + return; ADFS (total%b[cur],cur+1, num+1); atDFS (total,cur+1, num); - } - - intMain () - { - //freopen ("In.txt", "R", stdin); in inti,t; -scanf"%d",&t); to while(t--) + { -ans= +; thescanf"%d%d",&m,&n); * for(i=0; i<m;i++) $scanf"%d",&b[i]);Panax NotoginsengSort (b,b+m,cmp); -DFS (N,0,0); the if(ans== +) +printf"-1\n"); A Else theprintf"%d\n", ans); + } - return 0; $}
HDU 5339 Untitled (Mob search)