[CF1016G]Appropriate Team
description
给你一个数组\(\{a_i\}\)以及\(X,Y\),问你有多少对\((i,j)\)满足存在一个\(v\in \mathbb{N}^+\)使得 \(\gcd(a_i,v)=X,\mbox{lcm}(a_j,v)=Y\)。\(i,j\)交换顺序被视为不同的数对,\(i,j\)可以相等。
\(n\le2\times10^5,a_i,X,Y\le10^{18}\)
sol
首先一定要有\(X|Y\),不然肯定无解。
假设\(Y=P_1^{mx_1}P_2^{mx_2}...P_k^{mx_k},X=P_1^{mn_1}P_2^{mn_2}...P_k^{mn_k}\)。
(\(mn_i\le mx_i\),\(mn_i\)可以为\(0\))
考虑如果\(\gcd(a_i,v)=X\),那么首先有\(X|a_i\),然后可以把\(a_i\)分解成\(a_i=P_1^{c_1}P_2^{c_2}...P_k^{c_k}\)。如果有某个\(c_i>mn_i\),那么\(v\)中\(P_i\)的次数就一定要是\(mn_i\)(不然\(\gcd\)中\(P_i\)的次数就大于\(mn_i\)了),否则可以任意。
我们状压记录对于每个\(a_i\),与它可以满足条件的\(v\)对于\(i\in[1,k]\)的\(P_i\)的次数是否一定要是\(mn_i\)。考虑到\(k\le15\),所以状态量也只有\(2^{15}\)。
然后我们考虑一个\(j\)可以和哪些\(i\)匹配。同理对于\(\mbox{lcm}(a_j,v)=Y\),我们也可以用一个\(2^{15}\)的状态表示\(P_i\)的次数是否一定要取\(mx_i\)。
剩下是工作就只有一个高维前缀和了。注意特判\(mn_i=mx_i\)的情况。
至于质因数分解。原题题解中有一种很神奇的方法。。。然而直接上\(\mbox{Pollard_Rho}\)不好吗。。。
code
#include<cstdio>
#include<algorithm>
#include<vector>
#include<ctime>
using namespace std;
#define ll long long
ll gi(){
ll x=0,w=1;char ch=getchar();
while ((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
if (ch=='-') w=0,ch=getchar();
while (ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
return w?x:-x;
}
const int N = 2e5+5;
const int M = 15;
int n,tot,all,mx[M],mn[M],c[1<<M];
ll G,L,a[N],P[M*5],ans;
ll mul(ll x,ll y,ll mod){
x%=mod;y%=mod;ll res=0;
while (y){
if (y&1) {res+=x;if (res>=mod) res-=mod;}
x+=x;if (x>=mod) x-=mod;y>>=1;
}
return res;
}
ll fastpow(ll x,ll y,ll mod){
ll res=1;
while (y){
if (y&1) res=mul(res,x,mod);
x=mul(x,x,mod);y>>=1;
}
return res;
}
ll f[]={2,3,5,7,11,13,17,19,23,29};
bool MR(ll p){
for (int i=0;i<10;++i){
if (p<=f[i]) break;
if (fastpow(f[i],p-1,p)!=1) return false;
ll pp=p-1;
while (~pp&1){
pp>>=1;ll y=fastpow(f[i],pp,p);
if (mul(y,y,p)==1&&y!=1&&y!=p-1) return false;
}
}
return true;
}
ll PR(ll n,ll c){
ll i=0,k=2,x,y;x=y=1+rand()%(n-1);
while (1){
x=(mul(x,x,n)+c)%n;
ll d=__gcd((y-x+n)%n,n);
if (d!=1&&d!=n) return d;
if (x==y) return n;
if (++i==k) y=x,k<<=1;
}
}
void fact(ll n,ll c){
if (n==1) return;
if (MR(n)) {P[tot++]=n;return;}
ll p=n;while (p==n) p=PR(n,c--);
fact(p,233);fact(n/p,233);
}
int main(){
srand(19260817);n=gi();G=gi();L=gi();
for (int i=1;i<=n;++i) a[i]=gi();
if (L%G) return puts("0"),0;
fact(L,233);sort(P,P+tot);tot=unique(P,P+tot)-P;
for (int i=0;i<tot;++i){
ll x=G;while (x%P[i]==0) ++mn[i],x/=P[i];
x=L;while (x%P[i]==0) ++mx[i],x/=P[i];
}
all=(1<<tot)-1;
for (int i=1;i<=n;++i)
if (a[i]%G==0){
int zt=0;
for (int j=0;j<tot;++j){
ll x=a[i];int d=0;
while (x%P[j]==0) ++d,x/=P[j];
if (d>mn[j]) zt|=1<<j;
}
++c[zt];
}
for (int j=0;j<tot;++j)
for (int i=0;i<=all;++i)
if (i&(1<<j)) c[i]+=c[i^(1<<j)];// sum of subset
for (int i=1;i<=n;++i)
if (L%a[i]==0){
int zt=0;
for (int j=0;j<tot;++j){
ll x=a[i];int d=0;
while (x%P[j]==0) ++d,x/=P[j];
if (d==mx[j]||mx[j]==mn[j]) zt|=1<<j;
}
ans+=c[zt];
}
printf("%I64d\n",ans);return 0;
}
[CF1016G]Appropriate Team的更多相关文章
- Configure a VLAN on top of a team with NetworkManager (nmcli) in RHEL7
SOLUTION VERIFIED September 13 2016 KB1248793 Environment Red Hat Enterprise Linux 7 NetworkManager ...
- Create a Team in RHEL7
SOLUTION VERIFIED September 13 2016 KB2620131 Environment Red Hat Enterprise Linux 7 NetworkManager ...
- Team Leader 你不再只是编码, 来炖一锅石头汤吧
h3{ color: #000; padding: 5px; margin-bottom: 10px; font-weight: bolder; background-color: #ccc; } h ...
- Configure bridge on a team interface using NetworkManager in RHEL 7
SOLUTION IN PROGRESS February 29 2016 KB2181361 environment Red Hat Enterprise Linux 7 Teaming,Bridg ...
- BZOJ 4742: [Usaco2016 Dec]Team Building
4742: [Usaco2016 Dec]Team Building Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 21 Solved: 16[Su ...
- 关于 feature team 的一些内容
矩阵式管理,是常见的经典管理架构.其最早起源于美国的航空航天部门,然后被美国人带到了日本,然后被日本人带到了台湾,然后台湾人带到大陆...矩阵管理最典型的特征是,组织架构按职能与专业划分,项目由跨越部 ...
- 病毒四度升级:安天AVL Team揭露一例跨期两年的电信诈骗进化史
自2014年9月起,安天AVL移动安全团队持续检测到一类基于Android移动平台的间谍类病毒,病毒样本大多伪装成名为"最高人民检察院"的应用.经过反编译逆向分析以及长期的跟踪调查 ...
- iOS 真机测试时报错:Provisioning profile "iOS Team Provisioning Profile: XXX” doesn't include the currently selected device “XXX”.
这几天因工作需要,去给客户演示iOS项目打包的过程.之前演示都是顺利的,但后来客户自己操作时打电话说遇到了问题,出现报错. 就过去看了一下,发现一个很陌生的错误提示: The operation co ...
- diff/merge configuration in Team Foundation - common Command and Argument values - MSDN Blogs
One of the extensibility points we have in Team Foundation V1 is that you can configure any other di ...
随机推荐
- node必知必会之node简介
1.什么是node.js 按照: Node.js官方网站主页 的说法: Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript ...
- Spring—Ioc
IoC容器,最主要的就是完成对象的创建以及维护对象的依赖关系等. 所谓控制反转,包括两部分:一是控制,二是反转,就是把传统方式需要由代码来实现对象的创建.维护对象的依赖关系,反转给容器来帮忙管理和实现 ...
- rails 日期取值
获取当前时间 当前时间 Time.now UTC时间, 国际标准时间 Time.now.utc 日相关 今日开始时间00:00:00 Time.now.beginning_of_day => 2 ...
- 2018-2019-1 20189215《Linux内核原理与分析》第三周作业
<庖丁解牛>第二章书本知识总结 函数调用框架 call指令有两个作用: (1) 将CS:EIP中下一条指令的地址A保存在栈顶: (2)设置CS:EIP指向被调用程序的第一行. ret指令在 ...
- JQuery实现锚点平滑滚动
一般使用锚点来跳转到页面指定位置的时候,会生硬地立即跳转到指定位置,但是有些时候我们想要平滑地过渡到指定的位置,那么可以使用JQuery简单的实现这个效果: 比如,这里我们将通过点击<a> ...
- OpenCV_火焰检测——完整代码
转:http://blog.csdn.net/xiao_lxl/article/details/43307993 火焰检测小程序 前几天,偶然看到了An Early Fire-Detection Me ...
- win10下搭建深度学习--总结【学习笔记】
win10 下搭建深度学习开发环境总结: 1.本人环境如下:win10,GTX1050TI.i7,anaconda3,vs2015,cuda9.0,cudnn7.1.4,tensorflow-gpu= ...
- 51Nod 1686 第K大区间(离散化+尺取法)
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1686 题意: 思路: 第K大值,所以可以考虑二分法,然后用尺取法去扫描, ...
- python 浮点数转分数
from fractions import Fraction value = 4.2 print(Fraction(value).limit_denominator())
- 使用dos2unix批量转换文件
使用dos2unix批量转换文件 dos2unix是Linux下的一个用户转换格式的程序,由于windows上文件的结束符和linux上的不同,那么在windows上编写的文件或者是脚本在Linux上 ...