思路:易知L不能整除G时为0;

将L/G质因数分解,对于其中的因子p,个数为cnt,则至少有一个包含p^cnt,至少有一个数不包含p;

只有一个数包含p^cnt时,有C(3,1);

有2个数包含p^cnt时,有C(3,1);

有2个数包含p因子,其中一个是p^cnt,另外一个有cnt-1种,总共有(cnt-1)A(3,2).

所以总共有6*cnt。

代码如下:

 #include<iostream>
#include<stdio.h>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<vector>
#define ll __int64
#define pi acos(-1.0)
#define MAX 50000
using namespace std;
int prime[MAX],cnt,e[MAX],lena;
bool f[MAX];
void init()
{
int i,j;
cnt=;
for(i=;i<MAX;i++){
if(f[i]==) prime[cnt++]=i;
for(j=;j<cnt&&i*prime[j]<MAX;j++){
f[i*prime[j]]=;
if(i%prime[j]==) break;
}
}
}
int solve(int n)
{
int i,j=,ans=;
for(i=;i<cnt&&prime[i]*prime[i]<=n;i++){
if(n%prime[i]==){
e[j]=;
n/=prime[i];
while(n%prime[i]==){
e[j]++;
n/=prime[i];
}
j++;
}
}
if(n>){
e[j++]=;
}
for(i=;i<j;i++){
ans*=*e[i];
}
return ans;
}
int main(){
int i,t,n,a,b,j,ans;
init();
scanf("%d",&t);
while(t--){
scanf("%d%d",&a,&b);
if(b%a) printf("0\n");
else printf("%d\n",solve(b/a));
}
return ;
}

hdu 4497 GCD and LCM的更多相关文章

  1. 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 ...

  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. HDU 4497 GCD and LCM(数论+容斥原理)

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

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

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

  5. hdu 4497 GCD and LCM (非原创)

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

  6. 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,求满 ...

  7. 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 * ...

  8. hdu 4497 GCD and LCM(2013 ACM-ICPC吉林通化全国邀请赛——题目重现)

    质分解 + 简单计数.当时去比赛的时候太年轻了...这道题都没敢想.现在回过头来做了一下,发现挺简单的,当时没做这道题真是挺遗憾的.这道题就是把lcm  / gcd 质分解,统计每个质因子的个数,然后 ...

  9. HDU 4497 GCD and LCM (分解质因数)

    链接 :  http://acm.hdu.edu.cn/showproblem.php?pid=4497 假设G不是L的约数 就不可能找到三个数. L的全部素因子一定包括G的全部素因子 而且次方数 ...

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

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

随机推荐

  1. Archiving

    There are typically four steps of archving: Preprocessing Write Store Delete   Normally Store is inv ...

  2. VS2010使用TeeChart5的ColorGrid绘制一维距离像

    绘制一维距离像原理:使用TeeChart控件中的ColorGrid显示(X,Y,Z)三维数据,X和Z分别代表一维距离像的x轴和y轴数据,Y代表对应的数值,以不同颜色显示. 1.注册TeeChart5 ...

  3. Cadence OrCad Allegro SPB 16.6 下载及安装破解指南

    Cadence公司的电子设计自动化产品涵盖了电子设计的整个流程,包括系统级设计,功能验证,IC综合及布局布线,模拟.混合信号及射频IC设计,全定制集成电路设计,IC物理验证,PCB设计和硬件仿真建模等 ...

  4. float闭合(清除浮动)和CSS HACK

    一.float 闭合(清除浮动) 将以下代码加入Global CSS 中,给需要闭合的div加上 class="clearfix" 即可,屡试不爽. <style>.c ...

  5. CentOS 6.4 升级 Mysq5.5l方法 和 用户远程登录数据库

    一:.在这里我们都知道 系统的yum源Mysql版本一般都是5.1 5.2的比较多 但是有些程序 必须要5.5以上的版本才能支持 这时候我们应该怎么办呢  编译安装也太慢 太费时间  那么我们就必要要 ...

  6. php 伪静态 (url rewrite mod_rewrite 重写)

    mod_rewrite是Apache的一个非常强大的功能,它可以实现伪静态页面.下面我详细说说它的使用方法!对初学者很有用的哦!1.检测Apache是否支持mod_rewrite通过php提供的php ...

  7. 边界函数Bounding Function(成长函数的上界)

    根据成长函数的定义,猜测    -->break point K restricts maximum possible mh(N) a lot for N>k bounding funct ...

  8. 【面试虐菜】—— Apache知识整理

    Apache性能调优1 Apache 部分:1. 移除不用的模块.2. 使用 mod_disk_cache NOT mod_mem_cache .3. 扁平架构配置mod_disk_cache.4.  ...

  9. linux c 打印彩色字符

    #include <stdio.h> #include <string.h> int main(int argc, char **argv) { , j = , str_len ...

  10. 11G RAC 简单命令

    1.查看集群状态: [root@rac1 ~]# su - grid [grid@rac1 ~]$ crsctl check clusterCRS-4537: Cluster Ready Servic ...