Codeforces Round #448 C. Square Subsets
题目链接
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的更多相关文章
- Codeforces Round #448(Div.2) Editorial ABC
被B的0的情况从头卡到尾.导致没看C,心情炸裂又掉分了. A. Pizza Separation time limit per test 1 second memory limit per test ...
- Codeforces Round #448
Pizza Serparation #include<stdio.h> #include<string.h> #include<stdlib.h> #include ...
- Codeforces Round #448 (Div. 2)C. Square Subsets
可以用状压dp,也可以用线型基,但是状压dp没看台懂... 线型基的重要性质 性质一:最高位1的位置互不相同 性质二:任意一个可以用这些向量组合出的向量x,组合方式唯一 性质三:线性基的任意一个子集异 ...
- 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 ...
- Codeforces Round #448 (Div. 2) B
题目描述有点小坑,ij其实是没有先后的 并且y并不一定存在于a中 判断y的个数和所给数组无关 对于2 - 7来说 中间满足%2==0的y一共有3个 2 4 6 这样 可以看出对于每个数字a 都能够二分 ...
- 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 ...
- 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 ...
- [Educational Codeforces Round 16]C. Magic Odd Square
[Educational Codeforces Round 16]C. Magic Odd Square 试题描述 Find an n × n matrix with different number ...
- Codeforces 895C - Square Subsets
895C - Square Subsets 思路:状压dp. 每个数最大到70,1到70有19个质数,给这19个质数标号,与状态中的每一位对应. 状压:一个数含有这个质因子奇数个,那么他状态的这一位是 ...
随机推荐
- 怎么修改oracle用户密码
在以SYSDBA身份登陆时可以修改其他用户的密码,比如: SQL> alter user user01 identified by user10;
- JQuery怎么实现页面左侧菜单刷新后保留鼠标点击addclass的样式?
$('ul.main-menu li a').each(function(){ if($($(this))[0].href==String(window.location)) $(this).pare ...
- js数据绑定(模板引擎原理)
<div> <ul id="list"> <li>11111111111</li> <li>22222222222< ...
- Jdk 和 Tomcat的 安装。
1.再分发服务器上下载JDK,然后利用xftp上传到聚石塔等 2. 解压: tar -zxvf jdk-8u121-linux-x64.tar.gz 3.配置环境变量: export JAVA_HOM ...
- IPC对象的持续性
转载:http://book.51cto.com/art/201006/207275.htm <UNIX网络编程:第2版.第2卷,进程间通信>本书全面深入地讲解了各种进程间通信形式,包括消 ...
- gcc/g++ 命令
gcc & g++现在是gnu中最主要和最流行的c & c++编译器 .g++是c++的命令,以.cpp为主,对于c语言后缀名一般为.c.这时候命令换做gcc即可.其实是无关紧要的.其 ...
- es6遍历数组forof
- Sqlserver双机热备文档(无域)
1. 配制环境 OS:Win7 DB:SQL Server R2 2. 基本配制 1. 开启sqlServer服务如下图-1 图-1 2. 开启sqlServer的tcp/i ...
- 企业级Docker Registry —— Harbor搭建和使用
本节内容: Harbor介绍 安装部署Harbor 环境要求 环境信息 安装部署harbor 配置harbor 配置存储 完成安装和启动harbor 访问Harbor 修改管理员密码 启动后相关容器 ...
- Linux--忘记MySQL密码的解决方法和输入mysqld_safe --skip-grant-tables &后无法进入MySQL的解决方法
https://blog.csdn.net/qq_35389417/article/details/78910974