zoukankan      html  css  js  c++  java
  • Hard GCD and LCM

    对于两个整数G和L(1<=G,L<=200000000),试找出使gcd(x, y, z) = G 和 lcm(x, y, z) = L的解(x,y,z)的个数。

    LSC被这道小学三年级的数学题难住了,聪明的你能帮帮他吗?

    注意:①  gcd是最大公约数,lcm是最小公倍数。

                ②(3,4,5)和(4,5,3)是不同的解。

                ③  第一行是样例个数T(1<=T<=10),接下来有T行,每行两个数字是G和L。

    样例输入:

    3

    3 72

    4 96

    5 93

    样例输出:

    108

    108

    0

     
     
     
     
    1. #include<stdio.h>
    2. #include<string.h>
    3. #include<math.h>
    4. int main(){
    5. int d[10000];
    6. int T, G, L, ans, i, num;
    7. scanf("%d ",&T);
    8. while(T--){
    9. memset(d,0,sizeof(d));
    10. num =0;
    11. scanf("%d %d",&G,&L);
    12. if(!(L % G)){
    13. L /= G;
    14. for(i =2; i <= sqrt(L); i++){
    15. if(!(L % i)){
    16. while(!(L % i)){
    17. d[num]++;
    18. L /= i;
    19. }
    20. num++;
    21. }
    22. }
    23. if(L !=1) d[num++]=1;
    24. ans =1;
    25. for(i =0; i < num; i++){
    26. ans *=6* d[i];
    27. }
    28. printf("%d ", ans);
    29. }else{
    30. printf("0 ");
    31. }
    32. }
    33. return0;
    34. }
     
  • 相关阅读:
    Junit连接oracle数据库
    java判断字符串是否由数字组成
    Hibernate各种主键生成策略与配置详解
    一对多映射关系
    one-to-one 一对一映射关系(转 wq群)
    工厂模式
    struts2
    创建JUtil
    jdbc
    压缩数据
  • 原文地址:https://www.cnblogs.com/sysu-zhengwsh/p/3674206.html
Copyright © 2011-2022 走看看