HDU-5833-Zhu and 772002【2016CCPC网络赛】【高斯消元】

原创 2016年08月30日 12:25:55

1002-Zhu and 772002


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

题目链接:HDU-5833

题目大意:给出n个数字,问有多少种方式取(1~n)个数字使得成为一个完美平方数

题目思路:这道的原题是sgu-200,另外白皮书上也有代码。

求完全平方数,质因子的范围也知道,所以我们可以对每个质因子列出一个模意义下的方程(mod 2),然后求变元的个数就行了。

ans=2^num-1(去掉全部为0)

如何求变元的个数,就是在高斯消元的时候对于一个未知数xi,如果后面的方程xi的系数都为0的话,那么这个就是一个变元。

参考博客:here

以下是代码:

#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
#define maxn 2100
ll vis[maxn];
ll prime[maxn]={0};
ll a[maxn];
ll fc[maxn][maxn]={{0}};
int n;
int pnum;
int get_primes(int m) {
    memset(vis, 0, sizeof(vis));
    int cnt = 1; //注意
    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;
}
void change(ll k,ll g)
{
    for(int i = 1; i <= pnum; )
    {
        if(k % prime[i] == 0)
        {
            fc[i][g] ^= 1;
            k /= prime[i];
        }
        else i++;
    }
    return;
}
ll gauss()
{
    ll g = 0;
    int i,j;
    for(j = 1; j <= n && g < pnum; j++)
    {
        for(i = g + 1; i <= pnum; i++)
            if(fc[i][j] == 1)
                break;
        if(i <= pnum)
        {
            g++;
            for(int p = j; p <= n; p++)
                swap(fc[g][p],fc[i][p]);
            for(int p = g + 1; p <= pnum; p++)
            {
                if(fc[p][j] == 1)
                {
                    for(int q = j; q <= n; q++)
                        fc[p][q] ^= fc[g][q];
                }
            }
        }
    }
    return g;
}
ll qpow(ll a,ll b,ll m)
{
    ll ans = 1;
    while(b){
        if(b & 1){
            ans = (ans * a) % m;
            b--;
        }
        b /= 2;
        a = a * a % m;
    }
    return ans;
}
int main(){
    int cas = 1;
    int t;
    cin >> t;
    get_primes(2100);
    pnum = 303;
    while(t--)
    {
        memset(fc,0,sizeof(fc));
        cin >> n;
        for (int i = 1; i <= n; i++) cin >> a[i],change(a[i],i);

        int r = gauss();  //求变元个数

        ll ans = qpow(2, (ll)(n - r), mod) - 1;
        printf("Case #%d:\n%lld\n",cas++,ans);
    }
}
版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

hdu 5833 Zhu and 772002 2016中国大学生程序设计竞赛 - 网络选拔赛1002 [质因子分解+高斯消元]【数论】

题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=5833 ——————————-. Zhu and 772002Time Limit: 2000/10...

HDU - 5833 Zhu and 772002(高斯消元解异或方程)

1表示的是这个数中这个素因子的次数为奇数,0表示为偶数。

Hdu 5833 Zhu and 772002(高斯消元解异或方程组)

题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=5833 思路: 将每个数质因数分解,若该位质因数指数为偶数,则该位a[i]为0,否则该位a[i]为1...

HDU5833(2016CCPC网赛)——Zhu and 772002(异或方程组,素数分解)

Zhu and 772002 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

hdu5833 Zhu and 772002 (高斯消元的简单应用)

hdu5833 Zhu and 772002 (高斯消元的简单应用):http://acm.hdu.edu.cn/showproblem.php?pid=5833 题面描述: Zhu and 77...

HDU 5833 Zhu and 772002 (高斯消元)

Zhu and 772002 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

HDU 5833 Zhu and 772002 (高斯消元)

Zhu and 772002 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) T...

HDU 5833 Zhu and 772002 高斯消元

原题见HDU 5833在nn个数中选择几个数aia_i相乘得到平方数,问有多少种取法。最大的素因子不超过2000,最后答案mod 1000000007。 (1≤n≤300,1≤ai≤1018)(1...

2016ccpc 1002(hdu5833)题解 (高斯消元求异或方程组自由变元)

比赛结束才知道是个高斯消元的题目,吓得我赶紧学了一发,然后惊讶的发现白皮书上原题QAQ. 由于刚学会,虽然是手敲但有些细节还是比对了模板,所以并不能解释,先放一发代码,等熟练了再补. 代码: #i...

2016中国大学生程序设计竞赛 - 网络选拔赛 1002 Zhu and 772002 hdu5833

Problem Description Zhu and 772002 are both good at math. One day, Zhu wants to test the ability ...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)