Ultraviolet A 11859-division game
Question Link
Question: Given a matrix, you can select a few numbers in a row and turn them into their factors. Finally, you cannot change the number of people and ask if you can win first.
Train of Thought: converting a factor is equivalent to deleting some prime numbers, which translates the problem into a nim game.
Code:
#include <stdio.h>#include <string.h>const int N = 10005;int t, n, m, num, cnt[N], vis[N], prime[N], pn = 0;int main() {for (int i = 2; i < N; i++) {if (vis[i]) continue;prime[pn++] = i;for (int j = i; j < N; j += i) {vis[j] = 1; } } for (int i = 2; i < N; i++) { int num = i; for (int j = 0; j < pn && prime[j] <= i; j++) { while (num % prime[j] == 0) { cnt[i]++; num /= prime[j]; } } } int cas = 0;scanf("%d", &t);while (t--) {int ans = 0;scanf("%d%d", &n, &m);for (int i = 0; i < n; i++) {int sum = 0; for (int j = 0; j < m; j++) { scanf("%d", &num);sum += cnt[num]; } ans ^= sum; } printf("Case #%d: %s\n", ++cas, ans == 0?"NO":"YES"); }return 0;}