BC #49 1001 Untitled

Untitled

 
 Accepts: 504
 
 Submissions: 1542
 Time Limit: 2000/1000 MS (Java/Others)
 
 Memory Limit: 65536/65536 K (Java/Others)
Problem Description

There is an integer aa and nn integers b_1, ldots, b_nb1​​,,bn​​. After selecting some numbers from b_1, ldots, b_nb1​​,,bn​​ in any order, say c_1, ldots, c_rc1​​,,cr​​, we want to make sure that a mod c_1 mod c_2 mod ldots mod c_r = 0a mod c1​​ mod c2​​ mod mod cr​​=0 (i.e., aa will become the remainder divided by c_ici​​ each time, and at the end, we want aa to become 00). Please determine the minimum value of rr. If the goal cannot be achieved, print -11 instead.

Input

The first line contains one integer T leq 5T5, which represents the number of testcases.

For each testcase, there are two lines:

  1. The first line contains two integers nn and aa (1 leq n leq 20, 1 leq a leq 10^61n20,1a106​​).

  2. The second line contains nn integers b_1, ldots, b_nb1​​,,bn​​ (forall 1leq i leq n, 1 leq b_i leq 10^61in,1bi​​106​​).

Output

Print TT answers in TT lines.

Sample Input
2
2 9
2 7
2 9
6 7
Sample Output
2
-1
 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <algorithm>
 4 using namespace std;
 5 char s[20005];
 6 int x[20005],y[20005],n,m;
 7 
 8 int judge(int a,int b)
 9 {
10     int flg=1;
11     while(a<b)
12     {
13         if(s[a]!=s[b])
14         {
15             flg=0;
16             break;
17         }
18         a++,b--;
19     }
20     return flg;
21 }
22 
23 int main()
24 {
25     int T;
26     int i,j;
27     scanf("%d",&T);
28     while(T--)
29     {
30         scanf("%s",s);
31         int l=strlen(s);
32         int oo=1;
33         for(i=1;i<l;i++)
34         {
35             if(s[i]!=s[i-1])
36             {
37                 oo=0;
38                 break;
39             }
40         }
41         if(oo==1)
42             printf("Yes
");
43         else
44         {
45         n=0,m=0;
46         x[0]=0,y[0]=l-1;
47         for(i=1;i<=l-3;i++)
48         {
49             if(judge(0,i)==1)
50             {
51                 n++;
52                 x[n]=i;
53             }
54         }
55         for(i=l-2;i>=2;i--)
56         {
57             if(judge(i,l-1)==1)
58             {
59                 m++;
60                 y[m]=i;
61             }
62         }
63         int ans=0;
64         for(i=0;i<=n;i++)
65         {
66             if(ans==1)
67                 break;
68             for(j=0;j<=m;j++)
69             {
70                 if(y[j]-x[i]<=1)
71                     break;
72                 if(judge(x[i]+1,y[j]-1)==1)
73                 {
74                     ans=1;
75                     break;
76                 }
77             }
78         }
79 
80         if(ans==1)
81             printf("Yes
");
82         else
83             printf("No
");
84         }
85     }
86     return 0;
87 }
View Code
原文地址:https://www.cnblogs.com/cyd308/p/4771339.html