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个质数标号,与状态中的每一位对应. 状压:一个数含有这个质因子奇数个,那么他状态的这一位是 ...
随机推荐
- xampp + windows 配置 memcache流程
1.运行xampp服务,打开phpinfo查看信息,如下图: 从上到下,依次为 PHP版本:5.6: architecture:x86: TS:线程安全: vc11 2.牢记以上几个横线内容之后去下载 ...
- 【navicat112_premium】navicat112_premium数据库连接工具安装过程
此工具及其方便,可以连接mysql.oracle.sqlserver登数据库... 1.下载安装包Navicat Premium_11.2.7简体中文版.rar 下载地址:http://qiaoliq ...
- 【技巧总结】Penetration Test Engineer[1]-Basic
1.渗透测试基础 1.1.渗透测试分类 黑盒测试:从远程网络位置来评估目标网络基础设施,没有任何相关信息 白盒测试:内部发起,了解到关于目标环境的所有内部与底层知识 灰盒测试:结合两者优势,根据对目标 ...
- 公司内网yum源
新增yum源配置文件 vi /etc/yum.repos.d/szyum.repo 内容如下: #[redhat6.3] [base] name=redhat63 baseurl=http://10. ...
- souce insight出错 There was an error opening project
souce insight出错 There was an error opening project: "...": Options->Preferences->Fol ...
- iframe 同域下父子页面的通信
//共同引用的JS文件 common.js ; (function (window, $) { $(function ($) { window.trip = window.trip || {}; wi ...
- overridePendingTransition()使用
实现两个 Activity 切换时的动画.在Activity中使用有两个参数:进入动画和出去的动画. 注意1.必须在 StartActivity() 或 finish() 之后立即调用.2.而且在 ...
- 21 JSON and Go go语言和json
JSON and Go 25 January 2011 Introduction JSON (JavaScript Object Notation) is a simple data intercha ...
- git —— 基本命令以及操作(No.1)
git基本命令(附加描述) 1.把文件添加到暂存区$ git add readme.txt 2.把暂存区的文件文件添加到仓库$ git commit -m "提交说明" 备注:ad ...
- 移动端布局 - REM方式
默认以宽度为640px的设计稿为基准页面,然后通过JS获取当前显示设备的尺寸,对应的调整 html 标签的font-size大小,从而实现通过以rem为单位的移动端布局适配. 具体代码 (functi ...