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个质数标号,与状态中的每一位对应. 状压:一个数含有这个质因子奇数个,那么他状态的这一位是 ...
随机推荐
- 【codeforces】【比赛题解】#915 Educational CF Round 36
虽然最近打了很多场CF,也涨了很多分,但是好久没写CF的题解了. 前几次刚刚紫名的CF,太伤感情了,一下子就掉下来了,不懂你们Div.1. 珂学的那场我只做了第一题……悲伤. 这次的Education ...
- mini2440的程序下载
mini2440拿到手有四天了,抱着很大的兴趣看韦东山老师的视频,但是因为电脑是win7 64bit的系统,dnw的驱动没有,经查询可以使用supervivi,就查找相关的资料.但是始终弄不好,后来使 ...
- haproxy代理https配置方法【转】
记得在之前的一篇文章中介绍了nginx反向代理https的方法,今天这里介绍下haproxy代理https的方法: haproxy代理https有两种方式:1)haproxy服务器本身提供ssl证书, ...
- 根据经纬度坐标计算距离-python
一.两个坐标之间距离计算 参考链接: python实现 1.Python 根据地址获取经纬度及求距离 2.python利用地图两个点的经纬度计算两点间距离 LBS 球面距离公式 美团app筛选“离我最 ...
- Flask:使用Eclipse+PyDev插件编辑基于package的项目
Windows 10家庭中文版,Python 3.6.4,Flask 1.0.2,Eclipse Oxygen.1a Release (4.7.1a),PyDev 6.3.2 本文记录了 使用Ecli ...
- 华夏部分互联网科技公司创始及IPO信息
时间:2018-04-19 前面整理了一些美国科技公司的信息,这篇文章整理的是我华夏的一些科技公司的信息. 华为.百度.阿里.腾讯.美团.携程.京东.小米.奇虎360……之后,其它一些公司,要么体量 ...
- 利用vw+rem实现移动web适配布局
基本概念 1.单位 Px(CSS pixels) 像素 (px) 是一种绝对单位(absolute units), 因为无论其他相关的设置怎么变化,像素指定的值是不会变化的 其实是相对于某个设备而言的 ...
- tf.summary.merge_all()
1.自动管理模式 summary_writer = tf.summary.FileWriter('E:/data/tensorflow-master/1.Cnn_Captcha/result/', f ...
- linux定时任务-cron
/sbin/service crond start //启动服务 /sbin/service crond stop //关闭服务 /sbin/service crond restart //重启服务 ...
- 获取随机字符串的方法 GetRandomString
方法1:推荐方便. System.Hash 单元 Memo1.Lines.Add(THash.GetRandomString(50)); 方法二(自己写的): function TStrApi.Sui ...