Ultraviolet A 11542, uva11542

Source: Internet
Author: User

Ultraviolet A 11542, uva11542
Ultraviolet A 11542-Square

Question Link

Q: given some numbers, make sure that these numeric quality factors do not exceed 500. Find the number of these numbers, and the product is the complete number. There are several selection methods.

Idea: After dividing each number into a quality factor, we find that if the number is a full limit, the number of each quality factor in the selected number must be an even number, in this way, each prime factor can list an exclusive or equation. If the number contains a prime factor, this unknown number exists. Then, Gaussian deyuan is used to obtain the number of free variables, each free variable can be selected or not selected. In this case (2 ^ number), the answer is the one that deducts nothing.

Code:

#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const long long N = 501;int t, n, a[N][N], Max, vis[N], pn = 0;long long prime[N];void get_prime() {    for (long long i = 2; i < N; i++) {if (vis[i]) continue;prime[pn++] = i;for (long long j = i * i; j < N; j += i)    vis[j] = 1;    }}int gauss() {    int i = 0, j = 0;    while (i <= Max && j < n) {int k = i;for (; k <= Max; k++)    if (a[k][j]) break;if (k != Max + 1) {    for (int l = 0; l <= n; l++)swap(a[i][l], a[k][l]);    for (int k = i + 1; k <= Max; k++) {if (a[k][j]) {    for (int l = j; l <= n; l++)a[k][l] ^= a[i][l];}    }    i++;}j++;    }    return n - i;}int main() {    get_prime();    scanf("%d", &t);    while (t--) {scanf("%d", &n);long long x;Max = 0;memset(a, 0, sizeof(a));for (int i = 0; i < n; i++) {    scanf("%lld", &x);    for (int j = 0; j < pn && prime[j] <= x; j++) {while (x % prime[j] == 0) {    a[j][i] ^= 1;    Max = max(Max, j);    x /= prime[j];}    }}printf("%lld\n", (1LL<<(gauss())) - 1);    }    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.