link:http://acm.hdu.edu.cn/showproblem.php?pid=4497

如果G%L != 0,说明一定无解。

把K = G / L质数分解,G / L = p1^t1 * p2^t2 * p3^t3 * ……;同时 x/= L, y/= L, z/=L,不影响结果。

假设三个数字的质数分解是:

x = p1^i1 * p2^i2 * p3^i3 * ……

y = p1^j1 * p2^j2 * p3^j3 * ……

z = p1^k1 * p2^k2 * p3^k3 * ……

要保证x, y, z互质,并且lcm(x, y, z) = K, 那么对于p1来说,i1, j1, k1里面一定有一个是0,并且一定有一个是t1,所以有3种情况:

0 0 t1          有3种

t1 t1 0         有3种

t1 0 1~t1-1  有(t1-1)*6种

一共是6*t1种。

根据乘法原理,总的种数是:6*t1 + 6*t2 + ……

 #include <iostream>
 #include <cstdio>
 #include <cstdlib>
 #include <cstring>
 #include <cmath>
 #include <cctype>
 #include <algorithm>
 #include <queue>
 #include <deque>
 #include <queue>
 #include <list>
 #include <map>
 #include <set>
 #include <vector>
 #include <utility>
 #include <functional>
 #include <fstream>
 #include <iomanip>
 #include <sstream>
 #include <numeric>
 #include <cassert>
 #include <ctime>
 #include <iterator>
 const int INF = 0x3f3f3f3f;
 ][] = {{-,},{,},{,-},{,},{-,-},{-,},{,-},{,}};
 using namespace std;
 #define LL __int64
 ;
 int prime[MAX];
 bool flag[MAX];
 int main(void)
 {
     #ifndef ONLINE_JUDGE
     freopen("in.txt", "r", stdin );
     #endif // ONLINE_JUDGE
     int t;
     scanf("%d", &t);
         memset(flag, true, sizeof(flag));
     ;
     ; i * i <= ; ++i)
     {
             if (flag[i])
                 ; j <= ; j+=i)
                     flag[j] = false;
     }
         ; i <= ; ++i) if(flag[i]) prime[cnt++] = i;
     while (t--)
     {
         int G, L;
         scanf("%d%d", &G, &L);
         ;
         if (L % G)
         {
             printf("0\n");
             continue;
         }
         int K = L / G, S = K;
         ; i < cnt; ++i)
         {
             if (prime[i] * prime[i] > S) break;
             )
             {
                 ;
                 )
                 {
                     K /= prime[i]; touch++;
                 }
                 ans *= touch * ;
             }
         }
         ) ans *= ;
         printf("%d\n", ans);
     }

     ;
 }

当你不明白一个东西的时候,就他妈的别用。

比如,ios::sync_with_stdio(false); 这货表示消除cin, cout 的输入输出缓存,如果混合使用cout, printf的时候,同时用cout的时候也用了endl(表示清空缓存),注意,在程序开头,已经打开消除cin, cout 的输入输出缓存这个开关了,这里又清空缓存,不是矛盾嘛!有意思的是,如果用c++交就会AC,用G++交就会WA,本来我想要输入输出快一点,结果弄巧成拙了。

还有一定要想清楚为什么要有71行。

参考:

https://www.byvoid.com/blog/fast-readfile/

http://www.cnblogs.com/cszero/archive/2012/02/11/Zero0ne.html

以后多注意这些东西。

嗨,中村。

hdu4497 GCD and LCM ——素数分解+计数的更多相关文章

  1. HDU4497 GCD and LCM(数论,质因子分解)

    HDU4497 GCD and LCM 如果 \(G \% L != 0\) ,那么输出 \(0\) . 否则我们有 \(L/G=(p_1^{r_1})\cdot(p_2^{r_2})\cdot(p_ ...

  2. HDU4497——GCD and LCM

    这个题目挺不错的,看到是通化邀请赛的题目,是一个很综合的数论题目. 是这样的,给你三个数的GCD和LCM,现在要你求出这三个数有多少种可能的情况. 对于是否存在这个问题,直接看 LCM%GCD是否为0 ...

  3. hdu4497 GCD and LCM

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

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

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

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

  6. HDU_3071 Gcd & Lcm game 【素数分解 + 线段树 + 状压】

    一.题目  Gcd & Lcm game 二.分析 非常好的一题. 首先考虑比较暴力的做法,肯定要按区间进行处理,对于$lcm$和$gcd$可以用标准的公式进行求,但是求$lcm$的时候是肯定 ...

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

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

  8. hdu_4497GCD and LCM(合数分解)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4497 GCD and LCM Time Limit: 2000/1000 MS (Java/Other ...

  9. HDU 4497 GCD and LCM(数论+容斥原理)

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

随机推荐

  1. (转) C/C++中const关键字详解

    文章转自  http://www.cnblogs.com/yc_sunniwell/archive/2010/07/14/1777416.html 为什么使用const?采用符号常量写出的代码更容易维 ...

  2. 基础笔记5(file)

    file 可以是目录和文件(只是是java程序与系统的文件进行一种关联) File file1 = new File("f:/mytest", "test5.txt&qu ...

  3. [SoapUI] SoapUI JDBC REST 连接 Netezza

    How to Connect to Server 1. Apply accounts that has permission to access Netezza system for host acc ...

  4. 解决安装vc2005运行库时提示Command line option syntax error.Type Command/?for Help

    安装vc2005运行库时提示 这是因为它要自解压到用户的临时文件夹下,如果用户名中带中文,就会报错. 简单的解决方法是,手动解压之,再安装 当然,你也可以修改用户名或者再新建个用户.

  5. iOS中的translucent和automaticallyAdjustsScrollViewInsets用法

    关于这两个属性我长话短说 具体的可以更具具体情况来设置: translucent用法 automaticallyAdjustsScrollViewInsets用法 translucent用法 iOS7 ...

  6. SAP NWBC for HTML and Desktop configuration steps[From sdn]

    Summary :- This dcoumnenst conatin the information about requirement , hardware , configuration step ...

  7. java开发前奏

    做java开发当然少不了jdk(java开发工具),那么今天就介绍一下jdk的安装和配置. JDK官网下载地址(建议去官网下载,免费的) http://www.oracle.com/technetwo ...

  8. C#中combobox不可编辑与不可选择

    不可编辑:comboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; 将Style属性改为csDropDownL ...

  9. dpkg命令的用法

    dpkg 是Debian package的简写,为”Debian“ 操作系统 专门开发的套件管理系统,用于软件的安装,更新和移除. 所有源自"Debian"的Linux的发行版都使 ...

  10. WC2015 酱油记

    这是真·酱油记! Day0 因为我们在上海,所以只要坐高铁就可以了2333.到了火车站以后我们坐大巴到学军中学恩,结果坐大巴的时间和做坐高铁的时间差不做←_←. 吐槽了一下住宿环境和课程表就已经晚上了 ...