Ultraviolet A 11859-division game (NIM game)

Source: Internet
Author: User
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;}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.