Original link https://www.cnblogs.com/zhouzhendong/p/CF1016G.html
Topic Portal-CF1016G
Test instructions
Exercises
It's too late today, pigeon pigeons, write tomorrow.
Code
#include <bits/stdc++.h>using namespace Std;typedef long long ll;typedef unsigned long long ull;typedef long double Ld;namespace Pollard_rho{int prime[9]={2,3,5,7,11,13,17,19,23}; ULL Rr;int pcnt; LL P[70];vector <LL> Res; ll R (ll MoD) {return (RR+=4179340454199820289LL)%mod;} ll Mul (ll x,ll y,ll MoD) {ll d= (LL) floor ((LD) x*y/mod+0.5); LL res=x*y-d*mod;if (res<0) Res+=mod;return Res;} ll Pow (ll x,ll y,ll MoD) {ll ans=1%mod;for (; Y;y>>=1,x=mul (X,x,mod)) if (y&1) Ans=mul (ans,x,mod); return ans;} BOOL Miller_rabin (LL N) {if (n<=1) return 0;for (int i=0;i<9;i++) if (N==prime[i]) return 1; LL d=n-1;int tmp=0;while (! ( d&1)) d>>=1,tmp++;for (int i=0;i<9;i++) {LL X=pow (prime[i],d,n), p=x;for (int j=1;j<=tmp;j++) {X=Mul (x, X,N); if (x==1&&p!=1&&p!=n-1) return 0;p=x;} if (x!=1) return 0;} return 1;} ll F (ll x,ll c,ll MoD) {return (Mul (x,x,mod) +c)%mod;} ll gcd (ll X,ll y) {return y?gcd (y,x%y): x;} ll Get_factor (ll c,ll N) {ll x=r (n), Y=f (X,c,n), P=n;while (x!=y&& (p==n| | P==1) {P=GCD (N,max (x-y,y-x)); X=f (x,c,n); Y=f (f (y,c,n), c,n);} return p;} void Pollard_rho (LL n) {if (n<=1) return;if (Miller_rabin (n)) {res.push_back (n); return;} while (1) {LL v=get_factor (R (n-1) +1,n); if (v!=n&&v!=1) {Pollard_rho (v); Pollard_rho (n/v); return;}} void work (LL N) {res.clear (); Pollard_rho (n);}} ll read () {ll x=0,f=1;char Ch=getchar (); while (!isdigit (CH) &&ch!= '-') Ch=getchar (); if (ch== '-') f=-1,ch= GetChar (); while (IsDigit (CH)) x= (x<<1) + (x<<3) +ch-48,ch=getchar (); return x;} const int N=200005;int N; LL X,y,a[n]; LL v[16],vc=0,xc[16],yc[16],c[16];vector <LL> mul_x; LL a[1<<15];void get_v () {memset (xc,0,sizeof xc); memset (yc,0,sizeof YC); Pollard_rho:: Work (y), Vector <LL> Xx=pollard_rho:: Res;sort (Xx.begin (), Xx.end ()), V[vc=1]=xx[0],yc[vc]=1;for ( int i=1;i<xx.size (); i++) if (xx[i]==xx[i-1]) yc[vc]++;elsev[++vc]=xx[i],yc[vc]=1; LL xv=x;for (int i=1;i<=vc;i++) while (xv%v[i]==0) xv/=v[i],xc[i]++;} void FWT (LL a[],int n,int flag) {for (int d=1;d<n;d<<=1) for (int i=0;i<n;i+= (d<<1)) for (int j=0;j<d;j++) A[i+j]+=a[i+j+d]*flag;} int main () {N=read (), X=read (), Y=read (), for (int i=1;i<=n;i++) A[i]=read (), if (y%x) {Putchar (' 0 '); return 0;} if (y==1) {int ans=0;for (int i=1;i<=n;i++) if (a[i]==1) ans++;p rintf ("%i64d", 1ll*ans*ans); return 0;} Get_v (); Mul_x.clear (); memset (a,0,sizeof A); for (int i=1;i<=n;i++) {if (a[i]%x==0) Mul_x.push_back (A[i]); if (y%a[i]==0) { memset (c,0,sizeof c); LL yv=a[i];for (int i=1;i<=vc;i++) while (yv%v[i]==0) yv/=v[i],c[i]++;int s=0;for (int i=1;i<=vc;i++) if (c[i]==yc[ I]) s|=1<< (i-1); a[s]++;}} FWT (a,1<<vc,1); ll ans=0;for (int i=0;i<mul_x.size (); i++) {ll now=mul_x[i];memset (c,0,sizeof c); LL yv=now;for (int i=1;i<=vc;i++) while (yv%v[i]==0) Yv/=v[i],c[i]++;int s= (1<<VC) -1;for (int i=1;i<=vc;i++ ) If (c[i]==xc[i]| | Xc[i]==yc[i]) s^=1<< (i-1); ans+=a[s];} printf ("%i64d", ans); return 0;}
Codeforces 1016G appropriate Team number theory FWT