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

传送门

Zhu and 772002

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

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中国大学生程序设计竞赛 - 网络选拔赛

题目大意:

给出 n 个整数,从中选出 1 个或者多个,使得选出的整数乘积是完全平方数。一共有多少种选

法?对 MOD 取模。

解题思路:

赛后群里说 原题,已然蒙逼,刘汝佳白书 P160 , 一样一样的!!!,唉,亏我们还在推了那么

久。。。

其实我是做过一个类似的题所以没用多长时间,那个题目链接传送门

其实,那个题跟这个题目是差不多的,看那个题目就可以了,这个题目就是在那个题目的基础上先

处理一下就行了。。。

My Code:

/**
2016 - 08 - 14 下午
Author: ITAK

Motto:

今日的我要超越昨日的我,明日的我要胜过今日的我,
以创作出更好的代码为目标,不断地超越自己。
**/

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const LL INF = 1e9+5;
const LL MAXN = 2e3+5;
const LL MOD = 1e9+7;
const double eps = 1e-7;
const double PI = acos(-1);
using namespace std;
/**+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/

LL equ, var;///equ个方程 var个变量
LL a[MAXN][MAXN];///增广矩阵
LL x[MAXN];///解的数目
bool free_x[MAXN];///判断是不是自由变元
LL free_num;///自由变元的个数
inline LL GCD(LL m, LL n)
{
    if(n == 0)
        return m;
    return GCD(n, m%n);
}
inline LL LCM(LL a, LL b)
{
    return a/GCD(a,b)*b;
}

LL Gauss()
{
    LL Max_r;///当前列绝对值最大的存在的行
    ///col:处理当前的列
    LL row=0;
    for(LL col=0; row<equ&&col<var; row++,col++)
    {
        Max_r = row;
        for(LL i=row+1; i<equ; i++)
            if(abs(a[i][col]) > abs(a[Max_r][col]))
                Max_r = i;

        if(Max_r != row)
            for(LL i=0; i<var+1; i++)
                swap(a[row][i], a[Max_r][i]);

        if(a[row][col] == 0)
        {
            row--;
            continue;
        }
        for(LL i=row+1; i<equ; i++)
        {
            if(a[i][col])
            {
                for(LL j=col; j<var; j++)
                {
                    a[i][j] ^= a[row][j];
                }
            }
        }
    }
    return row;
}
const LL MAX = 2e3+5;
LL p[MAX];
bool prime[MAX];
LL k;
void isprime()
{
    k = 0;
    memset(prime, false, sizeof(prime));
    for(LL i=2; i<MAX; i++)
    {
        if(!prime[i])
        {
            p[k++] = i;
            for(LL j=i*i; j<MAX; j+=i)
                prime[j] = true;
        }
    }
}
LL quick_mod(LL a, LL b)
{
    LL ans = 1;
    while(b)
    {
        if(b & 1)
            ans = (ans*a)%MOD;
        b>>=1;
        a = (a*a)%MOD;
    }
    return ans;
}
int main()
{
    isprime();
    equ = k;
    LL T, n;
    scanf("%I64d",&T);
    for(LL cas=1; cas<=T; cas++)
    {
        cin>>var;
        memset(a, 0, sizeof(a));
        for(LL i=0; i<var; i++)
        {
            LL x;
            LL sum;
            scanf("%I64d",&x);
            for(LL j=0; j<equ; j++)
            {
                sum = 0;
                if(x%p[j] == 0)
                {
                    LL mm = x;
                    while(mm%p[j]==0)
                    {
                        sum++;
                        mm /= p[j];
                    }
                }
                ///构造系数矩阵
                if(sum & 1)
                    a[j][i] = 1;
                else
                    a[j][i] = 0;
            }
        }
        LL ans = var - Gauss();
        LL ret = quick_mod(2LL, ans);
        ret--;
        ret = (ret%MOD+MOD)%MOD;
        printf("Case #%I64d:\n%I64d\n",cas,ret);
    }
    return 0;
}
时间: 2024-12-30 11:13:59

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

HDU 5832 A water problem(取模~)—— 2016中国大学生程序设计竞赛 - 网络选拔赛

传送门 A water problem Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 60    Accepted Submission(s): 37 Problem Description Two planets named Haha and Xixi in the universe and they were created wit

2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6154 CaoHaha&#39;s staff 思维

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6154 题意:在笛卡尔坐标系下,画一个面积至少为  n 的简单多边形,每次只能画一条边或者一个格子的对角线,问至少要画几条. 解法:如果一个斜着的矩形长宽分别是 a,b,那么它的面积是 2ab.最优解肯定是离 sqrt(n/2)很近的位置.想想 n=5 时答案为什么是7 然后在那个小范围内枚举一下就好了.我给一张做题时画的图 #include <bits/stdc++.h> using namesp

2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6154 CaoHaha&#39;s staff(几何找规律)

Problem Description "You shall not pass!"After shouted out that,the Force Staff appered in CaoHaha's hand.As we all know,the Force Staff is a staff with infinity power.If you can use it skillful,it may help you to do whatever you want.But now,hi

2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6155 Subsequence Count 矩阵快速幂

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6155 题意: 题解来自:http://www.cnblogs.com/iRedBean/p/7398272.html 先考虑dp求01串的不同子序列的个数. dp[i][j]表示用前i个字符组成的以j为结尾的01串个数. 如果第i个字符为0,则dp[i][0] = dp[i-1][1] + dp[i-1][0] + 1,dp[i][1] = dp[i-1][1] 如果第i个字符为1,则dp[i][1

2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6153 A Secret KMP,思维

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6153 题意:给了串s和t,要求每个t的后缀在在s中的出现次数,然后每个次数乘上对应长度求和. 解法:关键在于想到把s和t都翻转之后,把t求next,然后用t去匹配s,在匹配过程中把fail指针跳到的地方加1,但是还没完,最后需要反向遍历第二个串将大串对小串的贡献加上去就可以了. 这道题是很多现场AC的代码是有漏洞的,比如bazbaba,bazbaba这个答案是34,但是很多现场AC的代码会输出31.

HDU 5916 Harmonic Value Description 【构造】(2016中国大学生程序设计竞赛(长春))

Harmonic Value Description Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 0    Accepted Submission(s): 0Special Judge Problem Description The harmonic value of the permutation p1,p2,?pn is ∑i=1

2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6150 Vertex Cover 二分图,构造

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6150 题意:"最小点覆盖集"是个NP完全问题 有一个近似算法是说-每次选取度数最大的点(如果有多个这样的点,则选择最后一个) 让你构造一个图,使得其近似算法求出来点数是你给定的覆盖点数的至少3倍. 解法: 可以把左边的点编号1~n,将左边的点进行n次分块,第i次分块中每块的大小为i,对于每一块的点,都在右边创建一个新节点与这些点相连. ①右边的点的度数为n,n-1,n-2,...,n/2,

2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6156 数位DP

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6156 题意:如题. 解法:数位DP,暴力枚举进制之后,就转化成了求L,R区间的回文数的个数,这个直接做一个数位DP就好了.dp[jz][start][cur][state]表示jz进制下以start位起始到cur位状态为state(1表示已经回文,0表示没有回文)时回文数的个数. #include <bits/stdc++.h> using namespace std; typedef long

hdu-5833 Zhu and 772002(高斯消元)

题目链接: Zhu and 772002 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1006    Accepted Submission(s): 348 Problem Description Zhu and 772002 are both good at math. One day, Zhu wants to test the