HDU 5339 Untitled (Mob search)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.