HDU 4497 数论+组合数学
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=4497
解题思路:将满足条件的一组x,z,y都除以G,得到x‘,y',z',满足条件gcd(x',y',x') = 1,同时lcm(x',y',x') = G/L.
特判,当G%L != 0 时,无解。
然后素数分解G/L,假设G/L = p1^t1 * p2^t2 *````* pn^tn。
满足上面条件的x,y,z一定为这样的形式。
x' = p1^i1 * p2^i2 *```* pn^in.
y' = p1^j1 * p2^j2 * ```*pn^jn.
z' = p1^k1 * p2^k2 * ```*pn^kn.
为了满足上面的条件,对于p1,一定有max(i1,j1,k1) = t1.min(i1,j1,k1) =0;则当选定第一个数为0,第二个数为t1时,第三个数可以为0-t1,又由于有顺序的,只有
(0,t1,t1) 和(0,t1,0)这两种情形根据顺序只能产生四种结果,其他的由于三个数都不一样,一定能产生6种,所以最后产生了6*(t1-1)+3*2 = 6*t1种,根据乘法原理以及关于素数分解的唯一性,反过来,素数组合必然也是唯一的数,一共有6*t1 * 6*t2 *`````*6*tn种选法。
另一种思考:容斥原理,对于p1,一共有(t1+1)^3种,但是没有最高位t1的选法是不合法的,减去,一共有t1^3种选法不合法,没有最低位0的选法是不合法的,也是t1^3,发现多减了,所以加上多减的既没有最高位也没有最低位的(t1-1)^3,通过化简得6*t1`````
贴代码:
#include<cstdio>
#include<cmath>
#define N 100005
int a[N],b[N];
void factor(int n,int &tot)
{
int temp,i;
temp =(int)(sqrt(n) +);
tot =-;
for(int i=; i <= temp; ++i)
{
if(n%i == )
{
a[++tot] = i;
b[tot] = ;
while(n%i == )
{
++b[tot];
n /= i;
}
}
}
if(n != )
{
a[++tot] = n;
b[tot] = ;
}
}
int main()
{
// freopen("in.txt","r",stdin);
int t,G,L;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&G,&L);
if(L%G != )
{
printf("0\n");
continue;
}
L = L/G;
int tot;
factor(L,tot);
long long int ans =;
for(int i=; i<=tot; ++i) ans *= (*b[i]);
printf("%I64d\n",ans);
}
return ;
}
HDU 4497 数论+组合数学的更多相关文章
- GCD and LCM HDU 4497 数论
GCD and LCM HDU 4497 数论 题意 给你三个数x,y,z的最大公约数G和最小公倍数L,问你三个数字一共有几种可能.注意123和321算两种情况. 解题思路 L代表LCM,G代表GCD ...
- HDU 4497 GCD and LCM (数论)
题意:三个数x, y, z. 给出最大公倍数g和最小公约数l.求满足条件的x,y,z有多少组. 题解:设n=g/l n=p1^n1*p2^n2...pn^nk (分解质因数 那么x = p1^x1 * ...
- 数论 - 组合数学 + 素数分解 --- hdu 2284 : Solve the puzzle, Save the world!
Solve the puzzle, Save the world! Problem Description In the popular TV series Heroes, there is a ta ...
- HDU 4497 GCD and LCM(数论+容斥原理)
GCD and LCM Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total ...
- 数论——算数基本定理 - HDU 4497 GCD and LCM
GCD and LCM Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total ...
- 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 ...
- HDU 4497 GCD and LCM(分解质因子+排列组合)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4497 题意:已知GCD(x, y, z) = G,LCM(x, y, z) = L.告诉你G.L,求满 ...
- HDU 4497 GCD and LCM (分解质因数)
链接 : http://acm.hdu.edu.cn/showproblem.php?pid=4497 假设G不是L的约数 就不可能找到三个数. L的全部素因子一定包括G的全部素因子 而且次方数 ...
- hdu 4542 数论 + 约数个数相关 腾讯编程马拉松复赛
题目:http://acm.hdu.edu.cn/showproblem.php?pid=4542 小明系列故事--未知剩余系 Time Limit: 500/200 MS (Java/Others) ...
随机推荐
- IBatis.net 输出SQL语句(七)
一.IBatis.net输出SQL语句到控制台 输出IBatis.net生成的SQL语句到控制台,能够方便调试. 如果要想输出IBatis.net的SQL语句到控制台,那么只需要做如下配置即可: &l ...
- ubuntu php.ini文件位置
mc@XJ > locate php.ini/etc/php5/cli/php.ini/etc/php5/fpm/php.ini
- SGU 140 扩展欧几里得
题目大意: 给定序列a[] , p , b 希望找到一个序列 x[] , 使a1*x1 + a2*x2 + ... + an*xn = b (mod p) 这里很容易写成 a1*x1 + a2*x2 ...
- plist 和 Xib
plist文件 mainbudin加载时候有后缀 xib文件 mainbudin加载时候无需后缀
- 中南民航如何利用K2BPM构建业务流程?
广州市中南民航空管通信网络科技有限公司成立于2004年9月,负责民航中南地区通信网络.电报网络的建设与维护.民航空管信息系统的开发与维护.公司拥有一支技术精湛的研发队伍,在信息技术领域领跑于民航空管行 ...
- java批量插入数据进数据库中
方式1: for循环,每一次进行一次插入数据. 方式2: jdbc的preparedStatement的batch操作 PreparedStatement.addBatch(); ...... Pre ...
- 《java作业》
/* 2.编写一个类,该类有一个方法public int f(int a,int b), 该方法返回a和b的最大公约数.然后再编写一个该类的子类, 要求子类重写方法f,而且重写的方法将返回a和b的最小 ...
- 打造高质量Android应用:Android开发必知的50个诀窍
打造高质量Android应用:Android开发必知的50个诀窍
- Chapter 5: Container
Chapter 5: Container A container is a module that processes the requests for a servlet and populates ...
- 一些需要注意的C知识点
1.数组在作为参数传递到函数时,会退化为一个指针.也就是说,一旦进入函数内部,数组已经变为了一个指针.其实是在参数传递的时候进行了浅拷贝,编译器会声明一个指针指向该数组,在函数内部所有的操作都是对该临 ...