Given the number of n, each step can replace a number with its factor, but it cannot be replaced with itself. When two people take turns, they will lose if they cannot leave. Ask who can win the game. If you win the game first, output the first step. N <= 0.1 million, each number <= 5000000.
Solution: Number theory + Nim. It seems like you have no idea at first, but I think: If you want to replace yourself with the factor of this question, you can start from here. Each number can be expressed as x = p1 ^ a1 * p2 ^ a2... pk ^ ak, pi is the prime number, so that each number is composed of (a1 + a2 + .. ak) is composed of several prime numbers, and then converted into several heap prime numbers. Each time, some prime numbers of a heap can be taken away and the final question is "no.
Isn't it the legendary bare Nim? Compare the quantity of each heap, and the result is 0 to the P state. If the result is not 0, the first hand wins. If the first hand wins, it must be able to change from a certain number to a p state. If the result is ans, if each digit is a [I], it is determined that the heap taken must meet the conditions: temp = a [t] ^ ans, temp <a [t], in this case, a [I] ^ a [j] ^... a [t] = ans can be expressed as a [I] ^ a [j] ^... temp ^ ans = ans, that is, a [I] ^ a [j] ^... ^ temp = 0.
I think A must solve this problem. The number of questions given in this question seems to be A little bloated. How can it be equal to 5 million? It hurt me a few times, and finally I had no choice but to use an array to save the smallest quality factor of each number, so each time I had to determine p1 ^ a1 * p2 ^ a2... when pk ^ ak is the sum of ai, as long as the minimum factor is continuously divided until there is no division, n becomes m, and m is continuously divided by the minimum factor of m, so that it is repeated until the value becomes 1.
Then we waited for the AC.
Test data:
4
111111 333333 4444444 5000000
10
1 2 3 4 5 6 7 8 9 10
4
111111 333333 4444444 5000000
5
1 3 5 7 9
4
1 3 5 7
4
1 3 5 5
4
5 5 5 5
5
5000000 5000000 5000000 5000000 1
5
5000000 4999999 4999999 4999999 4999998
3
1 2 4
Test #1: Alice 4
Test #2: Alice 4
Test #3: Alice 4
Test #4: Alice 5
Test #5: Alice 2
Test #6: Alice 2
Test #7: Bob
Test #8: Bob
Test #9: Alice 1
Test #10: Alice 3
C producer code:
[Cpp]
# Include <stdio. h>
# Include <math. h>
# Include <string. h>
# Define MIN 110000
# Deprecision MAX 5000010
Int cnt, n, ans;
Int Count [MAX], arr [MIN];
Int pn, prime [MAX], Min_factor [MAX];
Void make_prime (){
Int I, j, x, pn = 0;
For (I = 2; I <MAX; I ++ ){
If (! Min_factor [I]) prime [pn ++] = I, Min_factor [I] = I;
For (j = 0; j <pn & prime [j] * I <MAX; j ++ ){
X = prime [j] * I;
Min_factor [x] = prime [j];
If (I % prime [j] = 0) break; // make sure that the calculation is not repeated
}
}
}
Int solve (int n ){
Int ans = 0;
While (n! = 1 ){
Int t = 0;
Int k = Min_factor [n];
While (n % k = 0)
N/= k, t ++;
Ans + = t;
}
Return ans;
}
Int main ()
{
Int I, j, k, cas = 0;
Make_prime ();
While (scanf ("% d", & n )! = EOF ){
Ans = 0, Count [1] = 0;
For (I = 1; I <= n; ++ I ){
Scanf ("% d", & arr [I]);
Arr [I] = solve (arr [I]);
Ans ^ = arr [I];
}
Printf ("Test # % d:", ++ cas );
If (ans = 0) printf ("Bob \ n"); // P state
Else {
For (I = 1; I <= n; ++ I)
If (ans ^ arr [I]) <arr [I]) {// N state, this condition must be removed and changed to p state.
Printf ("Alice % d \ n", I); www.2cto.com
Break;
}
}
}
}
Author: woshi250hua