题目链接

Codeforces Round #448 C. Square Subsets

题解

质因数 *质因数 = 平方数,问题转化成求异或方程组解的个数

求出答案就是\(2^{自由元-1}\) ,高消求一下矩阵的秩,完了

或者

由于数很小, 我们只需要对于每个数的质因数装压

对这组数求线性基,n - 线性基中的数就是自由元个数

代码

#include<bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0,f = 1;
char c = getchar();
while(c < '0' ||c > '9')c = getchar();
while(c <= '9' &&c >= '0')x = x * 10 + c - '0',c = getchar();
return x * f ;
}
#define mod 1000000007
#define int long long
#define LL long long
int a[100005],b[21],n;
int prime[21] = {2 , 3 , 5 , 7 , 11 , 13 , 17 , 19 , 23 , 29 , 31 , 37 , 41 , 43 , 47 , 53 , 59 , 61 , 67};
LL Pow(LL x,int y) {
LL ret = 1;
for(;y;y >>= 1,x = x * x % mod) if(y & 1) ret = ret * x % mod;
return ret;
}
main() {
n = read();
for(int x,i = 1;i <= n;++ i) {
x = read();
for(int k,j = 0;j <= 18;++ j) {
k = 0;
while(x % prime[j] == 0) x /= prime[j],k ^= 1;
a[i] |= k * (1 << j);
}
}
for(int i = 1;i <= n;++ i)
for(int j = 18;j >= 0;-- j)
if(a[i] & (1 << j)) {
if(!b[j]) {
b[j] = a[i];
break;
} else a[i] ^= b[j];
}
for(int j = 0;j <= 18;j ++)
if(b[j]) n --;
printf("%I64d\n",(Pow(2ll,n) - 1 + mod) % mod) ;
return 0;
}

Codeforces Round #448 C. Square Subsets的更多相关文章

  1. Codeforces Round #448(Div.2) Editorial ABC

    被B的0的情况从头卡到尾.导致没看C,心情炸裂又掉分了. A. Pizza Separation time limit per test 1 second memory limit per test ...

  2. Codeforces Round #448

    Pizza Serparation #include<stdio.h> #include<string.h> #include<stdlib.h> #include ...

  3. Codeforces Round #448 (Div. 2)C. Square Subsets

    可以用状压dp,也可以用线型基,但是状压dp没看台懂... 线型基的重要性质 性质一:最高位1的位置互不相同 性质二:任意一个可以用这些向量组合出的向量x,组合方式唯一 性质三:线性基的任意一个子集异 ...

  4. Educational Codeforces Round 11 E. Different Subsets For All Tuples 动态规划

    E. Different Subsets For All Tuples 题目连接: http://www.codeforces.com/contest/660/problem/E Descriptio ...

  5. Codeforces Round #448 (Div. 2) B

    题目描述有点小坑,ij其实是没有先后的 并且y并不一定存在于a中 判断y的个数和所给数组无关 对于2 - 7来说 中间满足%2==0的y一共有3个 2 4 6 这样 可以看出对于每个数字a 都能够二分 ...

  6. Codeforces Round #448 (Div. 2) B. XK Segments【二分搜索/排序/查找合法的数在哪些不同区间的区间数目】

    B. XK Segments time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  7. Codeforces Round #448 (Div. 2) A. Pizza Separation【前缀和/枚举/将圆(披萨)分为连续的两块使其差最小】

    A. Pizza Separation time limit per test 1 second memory limit per test 256 megabytes input standard ...

  8. [Educational Codeforces Round 16]C. Magic Odd Square

    [Educational Codeforces Round 16]C. Magic Odd Square 试题描述 Find an n × n matrix with different number ...

  9. Codeforces 895C - Square Subsets

    895C - Square Subsets 思路:状压dp. 每个数最大到70,1到70有19个质数,给这19个质数标号,与状态中的每一位对应. 状压:一个数含有这个质因子奇数个,那么他状态的这一位是 ...

随机推荐

  1. 【译】第一篇 Integration Services:SSIS是什么

    本篇文章是Integration Services系列的第一篇,详细内容请参考原文. Integration Services是一种在SQL Server中最受欢迎的子系统.允许你在各种数据源之间提取 ...

  2. 解决 Electron 包下载太慢问题

    项目下新建 .npmrc 文件,加入如下配置: electron_mirror=https://npm.taobao.org/mirrors/electron/ 即使用淘宝的源,重新 npm inst ...

  3. gnome桌面无法使用笔记本的触摸板

    原来使用ubuntu的时候,升级了gnome之后触摸板就不能用了,不能说不能用了,应该是自己不会配置然后不好用了,具体状况如是,可以在登录界面gdm使用触摸板以及点击,但是进入桌面之后就不能点击了.后 ...

  4. qt中int与string的相互转换

    我经常搞错这个问题,一直以为整形int b可以直接使用函数toString呢! 但是在qtCreator中在整形后面不管怎么按点(可以自动提示)他就是不给我提示,我就纳闷了这样居然不行 百度了之后才知 ...

  5. Shell-修改MySQL默认root密码

    Code: mysqltmppwd=`cat /tmp/.mysql_secret | cut -b 87-102` mysqladmin -u root -p${mysqltmppwd} passw ...

  6. 一步一步搭建11gR2 rac+dg之DG 机器配置(七)【转】

    DG 机器配置 转自: 一步一步搭建11gR2 rac+dg之DG 机器配置(七)-lhrbest-ITPUB博客http://blog.itpub.net/26736162/viewspace-12 ...

  7. Pytorch数据变换(Transform)

    实例化数据库的时候,有一个可选的参数可以对数据进行转换,满足大多神经网络的要求输入固定尺寸的图片,因此要对原图进行Rescale或者Crop操作,然后返回的数据需要转换成Tensor如: import ...

  8. mysql高可用架构 -> MHA部署-04

    MHA架构图 本次MHA的部署基于GTID复制成功构建,普通主从复制也可以构建MHA架构. 下载所需的软件包 mkdir /server/tools -p //创建存放包的目录 [root@db01 ...

  9. unity 优秀开源项目

    ihaiu.GUIDRef (查看项目资源使用情况) http://blog.ihaiu.com/unity-GUIDRef Ihaiu.PoolManager (对象池) http://github ...

  10. 01 Getting Started 开始

    Getting Started 开始 Install the Go tools Test your installation Uninstalling Go Getting help   Downlo ...