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

统计的时候假如有2个3,这样的话肯定是有一个元素是含有全部的2个3的,也肯定有一个元素没有3,于是我们就可以直接得出,统计个数为元素个数x6, 然后每个质因子分配情况互不影响,于是可以用乘法原理。就可以得出最终答案了。

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<cmath> #define LL long long
#define CLR(a, b) memset(a, b, sizeof(a))
#define SL(a) strlen(a) using namespace std; const int N = 111111; vector<int> hav;
bool isp[N];
int p[N], cnt; void getp()
{
int i, j;cnt = 0;
isp[0] = isp[1] = 1;
for(i = 2; i < N; i ++)
{
if(!isp[i])
{
p[cnt ++] = i;
if(i <= 1111)for(j = i * i; j < N; j += i) isp[j] = 1;
}
}
} void get_hav(int h)
{
int i;
for(i = 0; i < cnt && h > 1; i ++)
{
if(h % p[i] == 0)
{
h /= p[i];
hav.push_back(p[i]);
i --;
}
}
if(!hav.size() && h != 1) hav.push_back(h);
} int main()
{
int l, g, i, num, t;
LL ans;
getp();
cin >> t;
while(t --)
{
cin >> g >> l;
if(l % g != 0) puts("0");
else
{
l /= g;
ans = 1;
hav.clear();
get_hav(l);
hav.push_back(-1);
num = 0;
for(i = 0; i < hav.size() - 1; i ++)
{
if(hav[i] == hav[i + 1])
{
num ++;
}
else
{
num ++;
ans *= (6 * num);
num = 0;
}
}
cout << ans << endl;
}
}
}

hdu 4497 GCD and LCM(2013 ACM-ICPC吉林通化全国邀请赛——题目重现)的更多相关文章

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

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

  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: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4 ...

  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 (分解质因数)

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

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

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

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

随机推荐

  1. windows7 64位下运行 regsvr32 注册ocx或者dll的方法

    来源:转载   it won't work for you unless you have some form of Visual Basic tools loaded on your system: ...

  2. windows环境中mysql忘记root密码的解决办法

    原文地址:http://www.cnblogs.com/linuxnotes/archive/2013/03/09/2951101.html windows下重置Mysql Root密码的方法mysq ...

  3. ElasticSearch Aggregation

    http://zaiste.net/2014/06/concisely_about_aggregations_in_elasticsearch/

  4. 如何在IE8下调试OCX控件

    第一种方式 多进程模式下, 在IE8打开web页面, 然后在调试菜单选择附加到进程, 这时看到2个IE进程, 选择没有带标题的, 也就是主进程, 就可以正常调试了. 此方式比较麻烦, 不能F5直接启动 ...

  5. redsocks 设置全局代理

    分享一下我的经验, http://lilydjwg.is-programmer.com/2014/2/7/linux-really-global-http-proxy.42701.html 1. 优点 ...

  6. http://docs.aliyun.com/#/rds/best-practices/collocation&security

    http://docs.aliyun.com/#/rds/best-practices/collocation&security

  7. 如何阅读mysql源码

    在微博上问mysql高手,如何阅读mysql 源码大致给了下面的一些建议: step 1,知道代码的组织结构(官方文档http://t.cn/z8LoLgh: Step2: 尝试大致了解一条sql涉及 ...

  8. Linux一键安装web环境全攻略(阿里云服务器)

    摘自阿里云服务器官网,此处 一键安装包下载: 点此下载 安装须知 1.此安装包可在阿里云所有linux系统上部署安装,此安装包包含的软件及版本为: nginx:1.0.15.1.2.5.1.4.4 a ...

  9. 前端开发工具—fiddle

  10. Objective-C基础笔记(2)@property和@synthesize

    先贴出使用@property和@synthesize实现的上一篇中的代码,再解释这两个keyword的使用方法和含义,代码例如以下: Person.h文件 #import <Foundation ...