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. My97日期控件 选择日期区间

    <script language="javascript" type="text/javascript" src="My97DatePicker ...

  2. NHibernate的使用

    本文档适合初级开发者或者是第一次接触NHibernate框架的朋友,其中NHibernate不是最新的版本,但是一个比较经典的版本 NHibernate 2.1.2,其中用红线标注的部分一定要仔细看, ...

  3. JQuery text()、html() 以及 val()

    获得内容 - text().html() 以及 val() 三个简单实用的用于 DOM 操作的 jQuery 方法: text() - 设置或返回所选元素的文本内容 html() - 设置或返回所选元 ...

  4. linux笔记:shell编程-正则表达式

    正则表达式与通配符(正则表达式匹配字符串,是包含匹配:通配符匹配文件名,是完全匹配.): 基础正则表达式: 正则表达式示例:

  5. HTML中的target(_self,_blank)用法总结

    HTML中的target(_self,_blank)用法总结 最近一个项目,多次遇到target='_self', target='_blank'的用法, 再次总结一下: 1.<a>标签 ...

  6. [转]不正当使用HashMap导致cpu 100%的问题追究

    以前项目中遇到类似业务,但使用的是CurrentHashMap,看到这篇文章,转载记录,警示自己. 以下内容转自: 转载自并发编程网 – ifeve.com(http://ifeve.com/hash ...

  7. bat脚本 -- 初步接触

    服务器上的Tomcat 经常过一段时间就会死掉,为了防治Tomcat突然当掉影响业务,设置一个定时重启计划. bat脚本如下: @echo restart tomcat6 service, log t ...

  8. PHP过滤外部链接及外部图片 添加rel="nofollow"属性

    原来站内很多文章都是摘录的外部文章,文章里很多链接要么是时间久了失效了,要么就是一些测试的网址,如:http://localhost/ 之类的,链接多了的话,就形成站内很多死链接,这对SEO优化是很不 ...

  9. 修改oracle字符集

    >sqlplus /nolog >conn / as sysdba sql>shutdown immediate sql>startup mount sql>ALTER ...

  10. transform scale