HDU 4497 GCD and LCM (分解质因数)
来源:互联网 发布:e4a操作数据库 编辑:程序博客网 时间:2024/05/17 20:56
链接 :
http://acm.hdu.edu.cn/showproblem.php?pid=4497
如果G不是L的约数 就不可能找到三个数。
L的所有素因子一定包含G的所有素因子 并且次方数一定大于等于G的。只需要三个数 对于每一个素因子的次方数 三个的最小值是G的,最大值是L的。考虑三个对应的次方数都不一样,那么其中两个是确定的 一个是G的一个是L的 剩下的一个在G和L的之间。算上排列 总共有6种。或者其中两个是一样的,那么也有6种情况。最后可以合并计算。
//#pragma comment(linker, "/STACK:10240000,10240000")#include <algorithm>#include <iostream>#include <sstream>#include <cstring>#include <cstdlib>#include <cstdio>#include <vector>#include <cmath>#include <queue>#include <stack>#include <set>#include <map>#define mod 4294967296#define MAX 0x3f3f3f3f#define lson o<<1, l, m#define rson o<<1|1, m+1, r#define SZ(x) ((int)ans.size())#define MAKE make_pair#define INFL 0x3f3f3f3f3f3f3f3fLL#define mem(a) memset(a, 0, sizeof(a))const double pi = acos(-1.0);const double eps = 1e-9;const int N = 200005;const int M = 20005;typedef __int64 ll;using namespace std;ll a, b;struct C { ll num, cnt;} s[N], t[N];int T;int Ini(ll a, C* f) { int tmp = sqrt(1.0*a + 0.5), e = 0; for(int i = 2; i <= tmp; i++) { if(a % i == 0) { int k = 0; while(a % i == 0) { k++; a /= i; } f[e].num = i; f[e++].cnt = k; } } if(a != 1) { f[e].cnt = 1; f[e++].num = a; } return e;}int main() { //freopen("in.txt","r",stdin); cin >> T; while(T--) { cin >> a >> b; if(b % a) { puts("0"); continue; } mem(s); mem(t); int n = Ini(a, s); int m = Ini(b, t); ll ans = 1, x; int fr = 0; for(int i = 0; i < m; i++) { if(t[i].num == s[fr].num) { x = t[i].cnt - s[fr].cnt; fr++; if(x) ans *= x * 6; } else ans *= t[i].cnt * 6; } cout << ans << endl; } return 0;}
1 0
- HDU 4497 GCD and LCM (分解质因数)
- HDU 4497 GCD and LCM (分解质因数)
- HDOJ 4497 GCD and LCM(质因数分解)
- hdoj 4497(gcd&lcm分解质因数)
- HDU 4497GCD and LCM(素数分解)
- hdu 4497 GCD and LCM (素数分解+组合数学)
- HDU 4497 GCD and LCM(唯一分解定理+排列组合)
- hdu 4497 GCD and LCM (唯一分解定理 + 计数)
- GCD and LCM 质因数分解与容斥原理
- Hdu4497 GCD and LCM 素数筛法+分解质因数
- hdu 4497 GCD and LCM(唯一分解+容斥原理)
- hdu 4497 GCD and LCM 数论 素数分解
- HDU 4497 - GCD and LCM (质因式分解 GCD LCM)
- HDU 4497 GCD and LCM(素因子分解+组合数学)
- POJ 2429 GCD & LCM Inverse(Pollard_rho法质因数分解)
- poj 2429 GCD & LCM Inverse(大数质因数分解+DFS)
- hdu(4497) GCD and LCM
- HDU 4497 GCD and LCM(数学)
- Python 基础语法(和Java相比)
- GNU Bison 中文手册
- Office打开时提示某个对象程序库(|)丢失或损坏
- php面向对象(OOP)—定义类
- linux编程学习4-从HelloWorld开始
- HDU 4497 GCD and LCM (分解质因数)
- 8.建立root以外的管理员用户
- VDA FunctionalLevel too low for Catalog
- IOC前世今生
- 学习记录:linux下将C程序编译为汇编程序进行分析
- 开发中常用服务集合(已完结)
- Sort it hdu 2689
- select into from与insert into select区别详解,sql语句复制表
- canvas笔记1