HDU - 4497 GCD and LCM 数论gcd

传送门

文章目录

题意:

给三个数的 l c m lcm lcm和 g c d gcd gcd,求满足条件的三元组组合个数。

思路:

首先 l c m   m o d   g c d = = 0 lcm\bmod gcd==0 lcmmodgcd==0是有组合的条件,否则输出0。
现在可知 l c m ( x ′ , y ′ , z ′ ) = l c m ( x , y , z ) g c d ( x , y , z ) , g c d ( x ′ , y ′ , z ′ ) = 1 lcm(x^{'},y^{'},z^{'})=\frac{lcm(x,y,z)}{gcd(x,y,z)},gcd(x^{'},y^{'},z^{'})=1 lcm(x′,y′,z′)=gcd(x,y,z)lcm(x,y,z)​,gcd(x′,y′,z′)=1,对 a a a分解质因子得到 p 1 u 1 p 2 u 2 . . . p n u n p_1^{u_1}p_2^{u_2}...p_n^{u_n} p1u1​​p2u2​​...pnun​​,假设 x ′ = p 1 i 1 p 2 i 2 . . . p n j n , y ′ = p 1 j 1 p 2 j 2 . . . p n j n , z ′ = p 1 k 1 p 2 k 2 . . . p n k n x^{'}=p_1^{i_1}p_2^{i_2}...p_n^{j_n},y^{'}=p_1^{j_1}p_2^{j_2}...p_n^{j_n},z^{'}=p_1^{k_1}p_2^{k_2}...p_n^{k_n} x′=p1i1​​p2i2​​...pnjn​​,y′=p1j1​​p2j2​​...pnjn​​,z′=p1k1​​p2k2​​...pnkn​​。那么由于 g c d ( x ′ , y ′ , z ′ ) = 1 gcd(x^{'},y^{'},z^{'})=1 gcd(x′,y′,z′)=1,可知 m i n ( i 1 , j 1 , k 1 ) = 0 min(i_1,j_1,k_1)=0 min(i1​,j1​,k1​)=0, m a x ( i 1 , j 1 , k 1 ) = u 1 max(i_1,j_1,k_1)=u_1 max(i1​,j1​,k1​)=u1​,所以我们需要找出来一个位置取 0 0 0,一个位置取 u 1 u_1 u1​,其他的位置随意就好了。当前位置的答案即为 A 3 2 ∗ u 1 = 6 ∗ u 1 A_3^2*u_1=6*u_1 A32​∗u1​=6∗u1​,那么 a n s = ∑ 6 ∗ u i ans=\sum6*u_i ans=∑6∗ui​。

    //#pragma GCC optimize(2)
#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<map>
#include<cmath>
#include<cctype>
#include<vector>
#include<set>
#include<queue>
#include<algorithm>
#include<sstream>
#include<ctime>
#include<cstdlib>
#define X first
#define Y second
#define L (u<<1)
#define R (u<<1|1)
#define pb push_back
#define mk make_pair
#define Mid (tr[u].l+tr[u].r>>1)
#define Len(u) (tr[u].r-tr[u].l+1)
#define random(a,b) ((a)+rand()%((b)-(a)+1))
#define db puts("---")
using namespace std;

//void rd_cre() { freopen("d://dp//data.txt","w",stdout); srand(time(NULL)); }
//void rd_ac() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//AC.txt","w",stdout); }
//void rd_wa() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//WA.txt","w",stdout); }

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;

const int N=1000010,mod=1e9+7,INF=0x3f3f3f3f;
const double eps=1e-6;

LL g,l;

int main()
{
//	ios::sync_with_stdio(false);
//	cin.tie(0);

    int _; scanf("%d",&_);
    while(_--)
    {
        scanf("%lld%lld",&g,&l);
        if(l%g!=0) { puts("0"); continue; }
        LL x=l/g;
        map<int,int>mp;
        for(int i=2;i<=x/i;i++)
            if(x%i==0)
                while(x%i==0) x/=i,mp[i]++;
        if(x>1) mp[x]++;
        LL ans=1;
        for(auto x:mp) ans*=6*x.Y;
        printf("%lld\n",ans);
    }



	return 0;
}
/*

*/


上一篇:Codeforces 1499D. The Number of Pairs(数学)


下一篇:[题解]luogu_P4161_(排列/lcm