codeforces

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的更多相关文章

  1. 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 ...

  2. Create a Team in RHEL7

    SOLUTION VERIFIED September 13 2016 KB2620131 Environment Red Hat Enterprise Linux 7 NetworkManager ...

  3. Team Leader 你不再只是编码, 来炖一锅石头汤吧

    h3{ color: #000; padding: 5px; margin-bottom: 10px; font-weight: bolder; background-color: #ccc; } h ...

  4. 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 ...

  5. BZOJ 4742: [Usaco2016 Dec]Team Building

    4742: [Usaco2016 Dec]Team Building Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 21  Solved: 16[Su ...

  6. 关于 feature team 的一些内容

    矩阵式管理,是常见的经典管理架构.其最早起源于美国的航空航天部门,然后被美国人带到了日本,然后被日本人带到了台湾,然后台湾人带到大陆...矩阵管理最典型的特征是,组织架构按职能与专业划分,项目由跨越部 ...

  7. 病毒四度升级:安天AVL Team揭露一例跨期两年的电信诈骗进化史

    自2014年9月起,安天AVL移动安全团队持续检测到一类基于Android移动平台的间谍类病毒,病毒样本大多伪装成名为"最高人民检察院"的应用.经过反编译逆向分析以及长期的跟踪调查 ...

  8. iOS 真机测试时报错:Provisioning profile "iOS Team Provisioning Profile: XXX” doesn't include the currently selected device “XXX”.

    这几天因工作需要,去给客户演示iOS项目打包的过程.之前演示都是顺利的,但后来客户自己操作时打电话说遇到了问题,出现报错. 就过去看了一下,发现一个很陌生的错误提示: The operation co ...

  9. 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 ...

随机推荐

  1. ruby中的win32ole使用

    ruby中的win32ole是一个标准库,使用的时候只要添加require 'win32ole'就行. 下面是一段模拟一个登陆的代码 require 'win32ole' ie = WIN32OLE. ...

  2. 网关服务Spring Cloud Gateway(一)

    Spring 官方最终还是按捺不住推出了自己的网关组件:Spring Cloud Gateway ,相比之前我们使用的 Zuul(1.x) 它有哪些优势呢?Zuul(1.x) 基于 Servlet,使 ...

  3. Putty出现 Network error:Software caused connection abort

    使用centos7.5 用Putty连接使用没多久就会出现 Network error:Software caused connection abort #修改sshd配置文件.修改3项配置即可 vi ...

  4. poj1985 / poj2631(树的直径)

    poj1985 Cow Marathon 树的直径裸题 树的直径的一般求法: 任意一点为起点,dfs/bfs找出与它最远的点$u$ 以$u$为起点,dfs/bfs找出与它最远的点$v$ 则$d(u,v ...

  5. linux第五周

    第五周 给MenuOS增加time和time-asm命令 更新menu代码到最新版 在main函数中增加MenuConfig 增加对应的Time函数和TimeAsm函数 make rootfs 使用g ...

  6. ESXi主机遗忘密码重置密码

    ESXi版本:6.0.0 VMware-VMvisor-Installer-6.0.0.update02-3620759.x86_64-Dell_Customized-A00.iso 使用和服务器系统 ...

  7. JS中innerHTML和innerText,outerHTML和outerText

      innerHTML 声明了元素含有的HTML文本,不包括元素本身的开始标记和结束标记 innerHTML是符合W3C标准的属性,而innerText只适用于IE浏览器(现在也适应chrome浏览器 ...

  8. 在 R 中使用 Python 字符串函数

    sprintf( )函数很强大,但并非适用于所有应用场景.例如,如果一些部分在模板中多次出现,那么就需要多次写一样的参数.这通常会使得代码冗长而且难以修改:sprintf("%s, %d y ...

  9. Chain of Responsibility(责任链)

    意图: 使多个对象都有机会处理请求,从而避免请求的发送者和接收者之间的耦合关系.将这些对象连成一条链,并沿着这条链传递该请求,直到有一个对象处理它为止. 适用性: 有多个的对象可以处理一个请求,哪个对 ...

  10. Android中的代理模式

    代理的概念:为某个对象提供一个代理,以控制对这个对象的访问. 代理类和委托类有共同的父类或父接口,这样在任何使用委托类对象的地方都可以用代理对象替代.代理类负责请求的预处理.过滤.将请求分派给委托类处 ...