博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
zcmu 1796 wjw的数学题 (唯一分解定理+排列组合)
阅读量:3899 次
发布时间:2019-05-23

本文共 2177 字,大约阅读时间需要 7 分钟。

【题目】

Problem B: wjw的数学题

Time Limit: 2 Sec  Memory Limit: 128 MB

Submit: 69  Solved: 24
[][][]

Description

Wjw recently encountered a mathematical problem .. given two positive integers x and y, how many kinds of schemes (a, b, c) make their gcd = x, lcm = y

 

Input

First line comes an integer T (T <= 12), telling the number of test cases.

The next T lines, each contains two positive  integers, x and y. The all input is guaranteed to be within the "int"

 

 

Output

For each test case, print one line with the number of solutions satisfying the conditions above.

 

Sample Input

2 6 72 7 33

Sample Output

72 0

【题意】

给定三个数的最大公约数x与最小公倍数y,问存在多少对符合要求的(a,b,c)。

【思路】

简单的思考一下,abc一定属于[x,y]并且是x的倍数,由此得若y%x!=0,则不存在,输出0。

根据唯一分解定理每个a,b,c都可以分成素数幂形式;

a=p1^a1*p2^a2*…pn^an;

b=p1^b1*p2^b2*…pn^bn;

c=p1^c1*p2^c2*…pn^cn;

gcd(a,b,c)=p1^min(a1,b1,c1)*…pn^min(an,bn,cn);

lcm(a,b,c)=p1^max(a1,b1,c1)*…pn^max(an,bn,cn);

显然对于每个质因数,只要三个数中有一个数的质因数的个数满足等于max(a,b,c)就可以了。这样来考虑的话,三个数都要有最大公约数的部分,其余的部分就是由lcm/gcd里面的质因子构成。这里面的因子可能会有 2 2 3 这样的情况, 不同的因子之间是不会相互干扰的,但是相同的会出现干扰,因为不能同时将相同的因子都放在三个位置上,这样最大公约数就的要乘上这个因子。对于单种因子来说,每种因子选择两个位置放置有 3 种情况,而两个位置里边选择一个位置放全部即n个因子有 2 种情况, 就有 3 *  2 =6 种情况,而另一个位置可以放0-n个因子有n种情况,这样化简后就是6 * n。由于不同因子互不干扰,所以最后的答案是各质因数的放置情况的乘积。

                                    对不起我没有脑子...

【代码】

#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define go(i,a,b) for(int i=a;i<=b;i++)#define og(i,a,b) for(int i=a;i>=b;i--)#define mem(a,b) memset(a,b,sizeof(a))#define Pi acos(-1)#define eps 1e-8using namespace std;typedef long long int ll;const int maxn=1e6;const int inf=0x3f3f3f3f;const int mod=1e9+7;bool number[maxn+5];int prime[maxn+5];void isprime(){ int i,j,c=0; memset(number,true,sizeof(number)); for(i=2;i<=maxn;i++) { if(number[i]) prime[c++]=i; for(j=0;j
<=maxn;j++) { number[prime[j]*i]=false; if(i%prime[j]==0) break; } }}main(){ isprime(); int t; scanf("%d",&t); while(t--) { int x,y; scanf("%d%d",&x,&y); if(y%x) { printf("0\n"); continue; } int c=1,n=y/x,i=0; while(prime[i]<=n) { if(n%prime[i]==0) { int sum=0; while(n%prime[i]==0) { n/=prime[i]; sum++; } c*=6*sum; } i++; } printf("%d\n",c); }}
你可能感兴趣的文章
JAVA人事管理系统
查看>>
Dubbo面试题(关注小R持续更新)
查看>>
JAVA仿微博系统(JAVA毕业设计含源码和运行教程)
查看>>
24BITBMP位图的文件结构及创建
查看>>
如何在自定义控件中获得width和height?
查看>>
Android UI开发专题之界面设计【基础API】
查看>>
ejarmaker: jar 、java类的加密工具
查看>>
配置NFS实现Linux服务器之间的文件共享
查看>>
PostgreSQL连接池pgbouncer的使用
查看>>
Kryo序列化进阶学习: 加密数据
查看>>
swift 3.0 数组赋值
查看>>
用C#通过888-TT打印中文标签
查看>>
sendmail 出现 My unqualified host name的解决办法
查看>>
彻底解决lazarus安装组件后烦人的编译时单元找不到的问题!
查看>>
Delphi的参数修饰const/var/output 与C++的对应关系
查看>>
C++ free与delete区别
查看>>
VC的字符串转换atlconv的使用
查看>>
Twitter的分布式自增ID算法snowflake (Java版)
查看>>
CentOS7 安装配置FastDFS
查看>>
递归算法的时间复杂度
查看>>