Luogu P1072 Hankson interesting question explanations

Cackle

Konjac continuous learning mathematics. . .

Face questions

Face questions

Solution

By the conditions \ (2 \) : \ (LCM (X, b_0) = B_1 \) can be derived \ (X \ MID B_1 \) .

We can enumerate \ (b_1 \) about the number of, if both of the conditions \ (1 \) and conditions \ (2 \) , then we will answer plus one.

Seen from trial division, enumerate all approximately logarithmic time complexity of a number of \ (O (\ sqrt {N}) \) . Since a plurality of sets of data, and also needs \ (GCD \) , so the overall complexity is \ (O (N \ CDOT \ B_1 sqrt {} \ CDOT \ B_1 log {}) \) .

Plus read and optimize output optimized to run quickly past.

Code

#include<bits/stdc++.h>
#define del(a,i) memset(a,i,sizeof(a))
#define ll long long
#define inl inline
#define il inl void
#define it inl int
#define ill inl ll
#define re register
#define ri re int
#define rl re ll
#define mid ((l+r)>>1)
#define lowbit(x) (x&(-x))
#define INF 0x3f3f3f3f
using namespace std;
template<class T>il read(T &x){
    int f=1;char k=getchar();x=0;
    for(;k>'9'||k<'0';k=getchar()) if(k=='-') f=-1;
    for(;k>='0'&&k<='9';k=getchar()) x=(x<<3)+(x<<1)+k-'0';
    x*=f;
}
template<class T>il print(T x){
    if(x/10) print(x/10);
    putchar(x%10+'0');
}
ll mul(ll a,ll b,ll mod){long double c=1.;return (a*b-(ll)(c*a*b/mod)*mod)%mod;}
it qpow(int x,int m,int mod){
    int res=1,bas=x%mod;
    while(m){
        if(m&1) res=(res*bas)%mod;
        bas=(bas*bas)%mod,m>>=1;
    }
    return res%mod;
}
int n,a,b,c,d,ans;
it gcd(int x,int y){return y==0?x:gcd(y,x%y);}
int main()
{
//  freopen(".in","r",stdin);
//  freopen(".out","w",stdout);
    read(n);
    while(n--){
        read(a),read(b),read(c),read(d),ans=0;
        for(ri i=1;i*i<=d;++i){
            if(d%i) continue;
            if(gcd(i,a)==b&&1ll*i*c/gcd(i,c)==d) ans++;
            if(i*i==d) break;
            if(gcd(d/i,a)==b&&1ll*d/i*c/gcd(d/i,c)==d) ans++;
        }
        print(ans);puts("");
    }
    return 0;
}

to sum up

Flexible application \ (a \ mid lcm (a , b) \) this conclusion.

Guess you like

Origin www.cnblogs.com/TheShadow/p/11391518.html