CF895C Square Subsets [线性基]
线性基的题…
考虑平方数只和拆解质因子的个数的奇偶性有关系
比如说你 \(4\) 和 \(16\) 的贡献都是一样的。因为
\(4 = 2^2 , 16 = 2^4\)
\(2\) 和 \(4\) 奇偶性相同
然后考虑如何线性基,不难想到,二进制可以表示奇偶性,
所以异或和每一位是0的时候就是一个平方数了。
我们考虑把 线性基的元素设为 \(|S|\) 个
那么你手头只剩下 \(n-|S|\) 个数字还可以被线性基表示的。
如果可以表示,那么说明了这些 \(2^{n-|S|}-1\) 个子集异或和都可以和线性基拼凑成0
所以目标答案就是 \(2^{n-|S|}-1\)
// by Isaunoya
#include <bits/stdc++.h>
using namespace std;
#define rep(i, x, y) for (register int i = (x); i <= (y); ++i)
#define Rep(i, x, y) for (register int i = (x); i >= (y); --i)
#define int long long
const int _ = 1 << 21;
struct I {
char fin[_], *p1 = fin, *p2 = fin;
inline char gc() {
return (p1 == p2) && (p2 = (p1 = fin) + fread(fin, 1, _, stdin), p1 == p2) ? EOF : *p1++;
}
inline I& operator>>(int& x) {
bool sign = 1;
char c = 0;
while (c < 48) ((c = gc()) == 45) && (sign = 0);
x = (c & 15);
while ((c = gc()) > 47) x = (x << 1) + (x << 3) + (c & 15);
x = sign ? x : -x;
return *this;
}
inline I& operator>>(double& x) {
bool sign = 1;
char c = 0;
while (c < 48) ((c = gc()) == 45) && (sign = 0);
x = (c - 48);
while ((c = gc()) > 47) x = x * 10 + (c - 48);
if (c == '.') {
double d = 1.0;
while ((c = gc()) > 47) d = d * 0.1, x = x + (d * (c - 48));
}
x = sign ? x : -x;
return *this;
}
inline I& operator>>(char& x) {
do
x = gc();
while (isspace(x));
return *this;
}
inline I& operator>>(string& s) {
s = "";
char c = gc();
while (isspace(c)) c = gc();
while (!isspace(c) && c != EOF) s += c, c = gc();
return *this;
}
} in;
struct O {
char st[100], fout[_];
signed stk = 0, top = 0;
inline void flush() {
fwrite(fout, 1, top, stdout), fflush(stdout), top = 0;
}
inline O& operator<<(int x) {
if (top > (1 << 20)) flush();
if (x < 0) fout[top++] = 45, x = -x;
do
st[++stk] = x % 10 ^ 48, x /= 10;
while (x);
while (stk) fout[top++] = st[stk--];
return *this;
}
inline O& operator<<(char x) {
fout[top++] = x;
return *this;
}
inline O& operator<<(string s) {
if (top > (1 << 20)) flush();
for (char x : s) fout[top++] = x;
return *this;
}
} out;
#define pb emplace_back
#define fir first
#define sec second
template < class T > inline void cmax(T & x , const T & y) {
(x < y) && (x = y) ;
}
template < class T > inline void cmin(T & x , const T & y) {
(x > y) && (x = y) ;
}
int ans = 0 ;
int p[30] ;
int pri[30] = { 2 , 3 , 5 , 7 , 11 , 13 , 17 , 19 , 23 , 29 , 31 , 37 , 41 , 43 , 47 , 53 , 59 , 61 , 67 } ;
void ins(int x) {
for(int i = 19 ; ~ i ; i --) {
if(x & (1 << i)) {
if(! p[i]) {
p[i] = x ;
}
x ^= p[i] ;
}
}
}
const int mod = 1e9 + 7 ;
int qpow(int x , int y) {
int ans = 1 ;
for( ; y ; y >>= 1 , x = x * x % mod)
if(y & 1) ans = ans * x % mod ;
return ans ;
}
signed main() {
#ifdef _WIN64
freopen("testdata.in" , "r" , stdin) ;
#endif
int n ;
in >> n;
rep(i , 1 , n) {
int x ;
in >> x ;
int res = 0 ;
rep(j , 0 , 18) {
if(x % pri[j] == 0) {
int now = 0 ;
while(x % pri[j] == 0) {
x /= pri[j] ;
now ^= 1 ;
}
res ^= (now << j) ;
}
}
ins(res) ;
}
for(int i = 19 ; ~ i ; i --) if(p[i]) n -- ;
out << ( qpow(2 , n) - 1 ) % mod << '\n' ;
return out.flush(), 0;
}
CF895C Square Subsets [线性基]的更多相关文章
- CF895C: Square Subsets && 【BZOJ2844】albus就是要第一个出场
CF895C: Square Subsets && [BZOJ2844]albus就是要第一个出场 这两道题很类似,都是线性基的计数问题,解题的核心思想也一样. CF895C Squa ...
- 洛谷CF895C Square Subsets(线性基)
洛谷传送门 不知道线性基是什么东西的可以看看蒟蒻的总结 题意: 给你n个数,每个数<=70,问有多少个集合,满足集合中所有数相乘是个完全平方数(空集除外) 题解: 完全看不出这玩意儿和线性基有什 ...
- [CF895C]Square Subsets
题目大意:给一个集合$S$($1\leq S_i\leq 70$),选择一个非空子集,使它们的乘积等于某个整数的平方的方法的数量. 求方案数,若两种方法选择的元素的索引不同,则认为是不同的方法. 题解 ...
- CF895C Square Subsets (组合数+状压DP+简单数论)
题目大意:给你一个序列,你可以在序列中任选一个子序列,求子序列每一项的积是一个平方数的方案数. 1<=a[i]<=70 因为任何一个大于2的数都可以表示成几个质数的幂的乘积 所以我们预处理 ...
- Codeforces 895C Square Subsets(状压DP 或 异或线性基)
题目链接 Square Subsets 这是白书原题啊 先考虑状压DP的做法 $2$到$70$总共$19$个质数,所以考虑状态压缩. 因为数据范围是$70$,那么我们统计出$2$到$70$的每个数的 ...
- UVA 11542 Square ——线性基
[题目分析] 每个数没有超过500的因子.很容易想到把每一个数表示成一个二进制的数. (0代表该质数的次数为偶数,1代表是奇数) 然后问题转化成了选取一些二进制数,使他们的异或和为0. 高斯消元,2^ ...
- Codeforces Round #448 C. Square Subsets
题目链接 Codeforces Round #448 C. Square Subsets 题解 质因数 *质因数 = 平方数,问题转化成求异或方程组解的个数 求出答案就是\(2^{自由元-1}\) , ...
- codeforces 1101G (Zero XOR Subset)-less 前缀异或+线性基
题目传送门 题意:给出一个序列,试将其划分为尽可能多的非空子段,满足每一个元素出现且仅出现在其中一个子段中,且在这些子段中任取若干子段,它们包含的所有数的异或和不能为0. 思路:先处理出前缀异或,这样 ...
- BZOJ 2844 albus就是要第一个出场 ——高斯消元 线性基
[题目分析] 高斯消元求线性基. 题目本身不难,但是两种维护线性基的方法引起了我的思考. void gauss(){ k=n; F(i,1,n){ F(j,i+1,n) if (a[j]>a[i ...
随机推荐
- 在家想自学Java,有C语言底子,请问哪本书适合?
一.问题剖析 看到这个问题,我想吹水两句再做推荐.一般发出这个疑问都处在初学编程阶段,编程语言都是相通的,只要你领悟了一门语言的"任督二脉",以后你学哪一门语言都会轻易上手.学语言 ...
- qt creator源码全方面分析(2-8)
目录 Editing MIME Types Editing MIME Types Qt Creator使用文件的MIME类型,来确定用于打开文件的模式和编辑器. 例如,Qt Creator在C++编辑 ...
- istio-ServiceMesh解决方案
istio-ServiceMesh解决方案 istio(1):ServiceMesh解决方案-k8s安装istio istio(2):流量管理-基于不同版本访问规则控制 istio(3):流量管理-基 ...
- Python 调用 Shell命令
python程序中调用shell命令,是件很酷且常用的事情今天来总结一下 1.使用os模块 的 system 此函数会启动子进程,在子进程中执行command,并返回comman ...
- apache主配置文件httpd.conf详解
[root@lamp conf]# vi httpd.conf.bak 1 # 2 # This is the main Apache HTTP server configuration file. ...
- Web渗透测试漏洞手册及修复建议
Web渗透测试漏洞手册及修复建议 0x0 配置管理 0x01 HTTP方法测试 漏洞介绍: 目标服务器启用了不安全的传输方法,如PUT.DELETE等,这些方法表示可能在服务器上使用了 WebDAV, ...
- 跨域打开页面:Uncaught DOMException: Blocked a frame with origin
Uncaught DOMException: Blocked a frame with origin 使用postMessage()方法可以解决跨域传值的问题 Api: https://develop ...
- R12客户表结构分析
客户表/联系人/PARTY关联 HZ_PARTIES 客户账户表 HZ_CUST_ACCOUNTS 例子: select hp.party_number --客户注册标识 ...
- asp.net abp模块化开发之通用树2:设计思路及源码解析
一.前言 上一篇大概说了下abp通用树形模块如何使用,本篇主要分析下设计思路. 日常开发中会用到很多树状结构的数据,比如:产品的多级分类.省市区县,大多数系统也会用到类似“通用字典/数据字典”的功能, ...
- .NET CORE(C#) WPF 值得推荐的动画菜单设计
微信公众号:Dotnet9,网站:Dotnet9,问题或建议:请网站留言, 如果对您有所帮助:欢迎赞赏. .NET CORE(C#) WPF 值得推荐的动画菜单设计 阅读导航 本文背景 代码实现 本文 ...