# 一道算法题，用的方法有点笨拙，一直AC不了

0
[待解决问题]

。如果多种情况都满足子列表长度最大，输出l最小的一个。如果不存在这样的子列表输出“None”。

3 4
2 3 5
4 9 25 6
3 4
2 3 5
6 6 3 3
0 0

1 3
1 4

1 import java.util.ArrayList;
2 import java.util.Scanner;
3
4 public class SquareNumber {
5
6     static int MAX_N = 30;
7     static int MAX_M = 30000;
8     static ArrayList<String> list = new ArrayList<>();
9
10     public static void main(String[] args) {
11         Scanner sc = new Scanner(System.in);
12         int[] A = new int[MAX_N];
13         int[] B = new int[MAX_M];
14         int N, M, i;
15         while (sc.hasNext()) {
16             N = sc.nextInt();
17             M = sc.nextInt();
18             if (M == 0 && N == 0){
19                 break;
20             }
21             for (i = 0; i < N; i++) {
22                 A[i] = sc.nextInt();
23             }
24             for (i = 0; i < M; i++) {
25                 B[i] = sc.nextInt();
26             }
27             squareNumber(A, B, N, M);
28         }
29         for (String s : list) {
30             System.out.println(s);
31         }
32     }
33     static void squareNumber(int[] A, int[] B, int N, int M) {
34         int i, j, k, t;
35         boolean flag;
36
37         int[] num = new int[MAX_N];
38         int temp = 1;
39
40         int len_max = 0;
41         int r = 0;
42         int f = 0;
43
44         for (i = 0; i < M; i++) {
45             for (j = i + 1 + len_max; j <= M; j++) {
46                 for (k = 0; k < N; k++) {
47                     num[k] = 0;
48                 }
49                 for (k = i; k < j; k++) {
50                     temp = B[k];
51                     while (temp != 1) {
52                         flag = false;
53                         for (t = 0; t < N; t++) {
54                             if (temp % A[t] == 0) {
55                                 temp /= A[t];
56                                 num[t]++;
57                                 flag = true;
58                             }
59                         }
60                         if (!flag) {
61                             return;
62                         }
63                     }
64                 }
65                 flag = true;
66                 for (k = 0; k < N; k++) {
67
68                     if (num[k] % 2 == 1) {
69                         flag = false;
70                         break;
71                     }
72                 }
73                 if (flag) {
74                     len_max = j - i;
75                     f = i + 1;
76                     r = j;
77                 }
78             }
79         }
80         if (f == 0 && r == 0) {