HDU 5833 Zhu and 772002 2016中国大学生程序设计竞赛 - 网络选拔赛(高斯消元)

来源:互联网 发布:nike官网抢鞋软件 编辑:程序博客网 时间:2024/06/01 15:29

Zhu and 772002

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 71 Accepted Submission(s): 24

Problem Description
Zhu and 772002 are both good at math. One day, Zhu wants to test the ability of 772002, so he asks 772002 to solve a math problem.

But 772002 has a appointment with his girl friend. So 772002 gives this problem to you.

There are n numbers a1,a2,…,an. The value of the prime factors of each number does not exceed 2000, you can choose at least one number and multiply them, then you can get a number b.

How many different ways of choices can make b is a perfect square number. The answer maybe too large, so you should output the answer modulo by 1000000007.

Input
First line is a positive integer T , represents there are T test cases.

For each test case:

First line includes a number n(1≤n≤300),next line there are n numbers a1,a2,…,an,(1≤ai≤1018).

Output
For the i-th test case , first output Case #i: in a single line.

Then output the answer of i-th test case modulo by 1000000007.

Sample Input
2
3
3 3 4
3
2 2 2

Sample Output
Case #1:
3
Case #2:
3

Author
UESTC

Source
2016中国大学生程序设计竞赛 - 网络选拔赛

Recommend
wange2014 | We have carefully selected several similar problems for you: 5842 5841 5840 5839 5838

原题醉了。。CCPC网络赛居然出原题。。UVA11542用亦或高斯消元一下

#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>#include <vector>typedef long long ll;using namespace std;const int maxn = 2005;typedef int Matrix[maxn][maxn];int prime[maxn], vis[maxn];Matrix A;int gen_primes(int m) {    memset(vis, 0, sizeof(vis));    int cnt = 0;    for (int i = 2; i < m; i++) {        if (!vis[i]) {            prime[cnt++] = i;            for (int j = i * i; j < m; j += i)                vis[j] = 1;        }    }    return cnt;}int rank1(Matrix A, int m, int n) {    int i = 0, j = 0, k , r, u;    while (i < m && j < n) {        r = i;        for (k = i; k < m; k++)            if (A[k][j]) {                r = k;                break;            }        if (A[r][j]) {            if (r != i)                for (k = 0; k <= n; k++)                    swap(A[r][k], A[i][k]);            for (u = i+1; u < m; u++)                if (A[u][j])                    for (k = i; k <= n; k++)                        A[u][k] ^= A[i][k];            i++;        }        j++;    }    return i;}int main() {    int m = gen_primes(2005);    int cas=1;    int t;    scanf("%d", &t);    while (t--) {        int n, maxp = 0;;        ll x;        scanf("%d", &n);        memset(A, 0, sizeof(A));        for (int i = 0; i < n; i++) {            scanf("%lld", &x);            for (int j = 0; j < m; j++)                 while (x % prime[j] == 0) {                    maxp = max(maxp, j);                    x /= prime[j];                    A[j][i] ^= 1;                }        }        int r = rank1(A, maxp+1, n);        //printf("Case #%d:\n%lld", cas++,(1ll << (n-r)) - 1);        long long ans=1;        for(int i=1;i<=n-r;i++)        {            ans*=2;            ans%=1000000007;        }        printf("Case #%d:\n%lld\n", cas++,ans-1);    }    return 0;}
0 0
原创粉丝点击