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

    题意:gcd(a,b,c)=g; lcm(a,b,c)=l; 求出符合的a,b,c的所有情况有多少中。

    思路:l/g=p1^x1*p2^x2*p3^x3.....;   x/g=p1^a1*p2^a2*p3^a3.....; b/g=p1^b1*p2^b2*p3^b3.....; c/g=p1^c1*p2^c2*p3^c3.....;

    在ai,bi,ci中至少有一个为0,至少有一个为x1,另一个的范围为0-x1;符合条件的方案数为 (x1+1)^3-(x1)^3-x1^3+(x1-1)^3; 总的情况数减去不含有0的情况和不含有x1的情况,再加上重复减去的;

     1 #include <cstdio>
     2 #include <cstring>
     3 #include <algorithm>
     4 #include <cmath>
     5 using namespace std;
     6 
     7 int t;
     8 int g,l;
     9 
    10 int main()
    11 {
    12     scanf("%d",&t);
    13     while(t--)
    14     {
    15         scanf("%d%d",&g,&l);
    16         if(l%g!=0)
    17         {
    18             printf("0
    ");
    19         }
    20         else
    21         {
    22             int m=l/g;
    23             __int64 ans=1;
    24             for(int i=2; i*i<=m; i++)
    25             {
    26                 if(m%i==0)
    27                 {
    28                     int cnt=0;
    29                     while(m%i==0)
    30                     {
    31                         m/=i;
    32                         cnt++;
    33                     }
    34                     ans*=((cnt+1)*(cnt+1)*(cnt+1)-cnt*cnt*cnt-cnt*cnt*cnt+(cnt-1)*(cnt-1)*(cnt-1));
    35                 }
    36             }
    37             if(m>1)
    38             {
    39                 ans*=6;
    40             }
    41             printf("%I64d
    ",ans);
    42         }
    43     }
    44     return 0;
    45 }
    View Code
  • 相关阅读:
    原生态 php连接mysql
    sql查询慢 查找
    死锁查询和处理
    linq详细案例
    linq深入
    DataTable 与XML 交互
    DataTable运用
    通过反射修改已有数组的大小
    通过反射取得并修改数组信息
    通过反射机制直接操作属性
  • 原文地址:https://www.cnblogs.com/fanminghui/p/4108959.html
Copyright © 2011-2022 走看看