|
| 1 | +```java |
| 2 | + |
| 3 | +import java.util.*; |
| 4 | +import java.io.*; |
| 5 | + |
| 6 | + |
| 7 | +class Main { |
| 8 | + |
| 9 | + // IO field |
| 10 | + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); |
| 11 | + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); |
| 12 | + static StringTokenizer st; |
| 13 | + |
| 14 | + static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());} |
| 15 | + static int nextInt() {return Integer.parseInt(st.nextToken());} |
| 16 | + static long nextLong() {return Long.parseLong(st.nextToken());} |
| 17 | + static void bwEnd() throws Exception {bw.flush();bw.close();} |
| 18 | + |
| 19 | + // Additional field |
| 20 | + static int N, M, K; |
| 21 | + static int[] C, A, L, D, R; |
| 22 | + static List<Integer> G; |
| 23 | + static int turnReverse; |
| 24 | + |
| 25 | + public static void main(String[] args) throws Exception { |
| 26 | + |
| 27 | + ready(); |
| 28 | + //solve(); |
| 29 | + |
| 30 | + bwEnd(); |
| 31 | + |
| 32 | + } |
| 33 | + |
| 34 | + static void ready() throws Exception{ |
| 35 | + |
| 36 | + int T = Integer.parseInt(br.readLine()); |
| 37 | + while(T-- > 0) { |
| 38 | + turnReverse = 0; |
| 39 | + nextLine(); |
| 40 | + N = nextInt(); |
| 41 | + M = nextInt(); |
| 42 | + C = new int[N+1]; |
| 43 | + TreeSet<Integer> temp = new TreeSet<>(); |
| 44 | + |
| 45 | + nextLine(); |
| 46 | + for(int i=0;i<M;i++) { |
| 47 | + int a = nextInt(), origin = a; |
| 48 | + if(a == 1) { |
| 49 | + turnReverse ^= 1; |
| 50 | + continue; |
| 51 | + } |
| 52 | + for(int j=2;j*j<=a;j++) { |
| 53 | + if(a%j != 0) continue; |
| 54 | + while(a%j == 0) a/=j; |
| 55 | + temp.add(j); |
| 56 | + } |
| 57 | + if(a > 75) { |
| 58 | + turnReverse ^= 1; |
| 59 | + continue; |
| 60 | + } |
| 61 | + if(a != 1) temp.add(a); |
| 62 | + C[origin]++; |
| 63 | + |
| 64 | + } |
| 65 | + K = temp.size(); |
| 66 | + L = new int[K]; |
| 67 | + int idx = 0; |
| 68 | + for(int i:temp) L[idx++] = i; |
| 69 | + |
| 70 | + G = new ArrayList<>(); |
| 71 | + for(int i=1;i<=N;i++) { |
| 72 | + int res = 0; |
| 73 | + if(C[i] == 0) continue; |
| 74 | + for(int j=0;j<K;j++) if((i % L[j]) == 0) { |
| 75 | + res |= (1<<j); |
| 76 | + } |
| 77 | + G.add(res); |
| 78 | + } |
| 79 | + |
| 80 | + D = new int[1<<K]; |
| 81 | + |
| 82 | + solve(); |
| 83 | + |
| 84 | + } |
| 85 | + |
| 86 | + } |
| 87 | + |
| 88 | + static void solve() throws Exception{ |
| 89 | + |
| 90 | + R = new int[G.size()]; |
| 91 | + for(int i=0;i<G.size();i++) R[i] = G.get(i); |
| 92 | + |
| 93 | + Arrays.fill(D, -1); |
| 94 | + bw.write(dp(0) == 1 ? "amsminn\n" : "bnb2011\n"); |
| 95 | + |
| 96 | + } |
| 97 | + |
| 98 | + static int dp(int n) { |
| 99 | + if(D[n] != -1) return D[n]; |
| 100 | + int can = 0; |
| 101 | + for(int r:R) if((n&r) == 0) { |
| 102 | + can++; |
| 103 | + if(dp(n|r) == 0) return D[n] = 1; |
| 104 | + } |
| 105 | + return D[n] = can == 0 ? turnReverse : 0; |
| 106 | + } |
| 107 | + |
| 108 | +} |
| 109 | + |
| 110 | +``` |
0 commit comments