题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4497

题意:

求有多少种(x,y,z)使得最小公倍数为l,最大公约数为g

分析:

我们将l,g进行素因子分解;

非常明显当g有l没有的素因子 和g的某一个因子的次数大于l的这个因子的次数的时候答案为0;

然后是有答案的情况下,我们设g中某一个因子数的次数为num1,l中这个因子的次数为num2;

那么在决定x,y,z在这个因子上的次数时我们要这样考虑,至少有一个为num1,至少有一个为

num2,然后依据容斥原理能够得出这样的情况的方案数

代码许下:

#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <map>
using namespace std; int G[2][50],L[2][50]; int gcd(int a,int b)
{
if(b) return gcd(b,a%b);
return a;
}
int main()
{
int t,g,l;
scanf("%d",&t);
while(t--){
scanf("%d%d",&g,&l);
int cnt1=0,cnt2=0;
memset(G,0,sizeof(G));
memset(L,0,sizeof(L));
map<int ,int >mp1;
map<int ,int >mp2;
for(int i=2;i<=g;i++){
if(g%i==0){
G[0][cnt1]=i;
while(g%i==0){
G[1][cnt1]++;
g/=i;
}
cnt1++;
}
}
if(g>1){G[0][cnt1]=g;G[1][cnt1++]=1;}
for(int i=2;i<=l;i++){
if(l%i==0){
L[0][cnt2]=i;
while(l%i==0){
L[1][cnt2]++;
l/=i;
}
cnt2++;
}
}
if(l>1) {L[0][cnt2]=l;L[1][cnt2++]++;}
bool flag=0;
for(int i=0;i<cnt1;i++)
mp1[G[0][i]]=G[1][i];
for(int i=0;i<cnt2;i++)
mp2[L[0][i]]=L[1][i];
for(int i=0;i<cnt1;i++){
if(mp1[G[0][i]]>mp2[G[0][i]])
flag=1;
}
if(flag){ puts("0"); continue;}
long long ans=1;
//cout<<cnt1<<" "<<cnt2<<endl;
/*****
cout<<"*******"<<endl;
for(int i=0;i<cnt1;i++)
cout<<G[0][i]<<" "<<G[1][i]<<endl;
cout<<"*******"<<endl;
for(int i=0;i<cnt2;i++)
cout<<L[0][i]<<" "<<L[1][i]<<endl;
cout<<"*******"<<endl;
******/
for(int i=0;i<cnt2;i++){
int num1=mp1[L[0][i]];
int num2=mp2[L[0][i]];
if(num1==num2) continue;
long long tmp = (num2-num1+1)*(num2-num1+1)*(num2-num1+1);
tmp-=2*(num2-num1)*(num2-num1)*(num2-num1);
tmp+=(num2-num1-1)*(num2-num1-1)*(num2-num1-1);
ans*=tmp;
cout<<"tmp "<<tmp<<endl;
}
cout<<ans<<endl;
}
return 0;
}

HDU44979 GCD and LCM (素因子分解+计数)的更多相关文章

  1. HDU 4497 GCD and LCM 素因子分解+ gcd 和 lcm

    题意: 给两个数,lll 和 ggg,为x , y , z,的最小公倍数和最大公约数,求出x , y , z 的值有多少种可能性 思路: 将x , y , z进行素因子分解 素因子的幂次 x a1 a ...

  2. 数论——算数基本定理 - HDU 4497 GCD and LCM

    GCD and LCM Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total ...

  3. HDOJ 4497 GCD and LCM

    组合数学 GCD and LCM Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others) ...

  4. hdu 4497 GCD and LCM 数学

    GCD and LCM Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4 ...

  5. GCD 与 LCM UVA - 11388

    题目链接: https://cn.vjudge.net/problem/23709/origin 本题其实有坑 数据大小太大, 2的32次方,故而一定是取巧的算法,暴力不可能过的 思路是最大公因数的倍 ...

  6. 简单数论总结1——gcd与lcm

    并不重要的前言 最近学习了一些数论知识,但是自己都不懂自己到底学了些什么qwq,在这里把知识一并总结起来. 也不是很难的gcd和lcm 显而易见的结论: 为什么呢? 根据唯一分解定理: a和b都可被分 ...

  7. poj 2429 GCD &amp; LCM Inverse 【java】+【数学】

    GCD & LCM Inverse Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9928   Accepted:  ...

  8. HDU 4497 GCD and LCM (合数分解)

    GCD and LCM Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total ...

  9. hdu4497 GCD and LCM

    GCD and LCM Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others) Total S ...

随机推荐

  1. 使用js获取url中的get参数并转成json格式

    写在前面的 没啥说的 上代码 思路就是先获取到?后面的参数区,然后 利用字符串转数组方法获取到各个参数 var json = {}; var url = 'https://www.baidu.com/ ...

  2. NodeJS 第一天学习

    NodeJS 第一天学习 严格模式 ECMAScript 5的严格模式是采用具有限制性JavaScript变体的一种方式,从而使代码显示地 脱离"马虎模式/稀松模式/懒散模式"(s ...

  3. rem — 一个低调的css单位

    原文  http://www.zhaoan.org/1825.html rem这是个低调的 css 单位,近一两年开始崭露头角,有许多同学对rem的评价不一,有的在尝试使用,有的在使用过程中遇到坑就弃 ...

  4. [NOIP2012提高组]疫情控制

    题目:洛谷P1084.codevs1218.Vijos P1783. 题目大意:有一棵n个节点的,根为1的带权树和m支军队.每支军队可以在一个点上停下,那么从1开始就不能经过这个点了.现在有m支军队已 ...

  5. luogu 4844 LJJ爱数数 (莫比乌斯反演+数学推导)

    题目大意:求满足gcd(a,b,c)==1,1/a+1/b=1/c,a,b,c<=n的{a,b,c}有序三元组个数 因为题目里有LJJ我才做的这道题 出题人官方题解https://www.cnb ...

  6. Axios 使用时遇到的问题

    最近使用 vue 构建一个小项目,在使用 axios 发送 post 请求的时候,发现 axios 发送数据默认使用 json 格式,百度搜了下,更改 ContentType 不管用,最终问题原来是: ...

  7. 2018秋寒假作业4——PTA编辑总结1

    #include<stdio.h> #include<math.h> int main(void) { int n,i,j,p,m,ge,N,k; char op; ){ sc ...

  8. Android里使用正則表達式

    在Android里怎样使用正則表達式: 以验证username为例.username一般字母开头,同意字母数字下划线.5-16个字节: String regEx = "^[a-zA-Z][a ...

  9. 如何解读「量子计算应对大数据挑战:中国科大首次实现量子机器学习算法」?——是KNN算法吗?

    作者:知乎用户链接:https://www.zhihu.com/question/29187952/answer/48519630 我居然今天才看到这个问题,天……本专业,有幸听过他们这个实验的组会来 ...

  10. nyoj--1011--So Easy[II](数学几何水题)

    So Easy[II] 时间限制:1000 ms  |  内存限制:65535 KB 难度:2 描述 这是一道基础的计算几何问题(其实这不提示大家也都看的出).问题描述如下: 给你一个N边形.且N边形 ...