zoukankan      html  css  js  c++  java
  • P1072 Hankson 的趣味题

    P1072 Hankson 的趣味题

    解法1:唯一分解定理

    通过$gcd$和$lcm$对$x$的质因数个数的限制,算出每个质因数的能取的$min~max$个数

    然后用乘法原理乘起来。

    解法2(code↓):

    考虑$lcm(x,b_{0})=b_{1}$

    转化一下:$x*b_{0}=b_{1}*gcd(x,b_{0})$

    $x=b_{1}/b_{0}*gcd(x,b_{0})$

    枚举一下$b_{0}$的因数,筛一筛就完事了

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<cmath>
     5 #include<cctype>
     6 #define re register
     7 using namespace std;
     8 void read(int &x){
     9     char c=getchar();x=0;
    10     while(!isdigit(c)) c=getchar();
    11     while(isdigit(c)) x=(x<<3)+(x<<1)+(c^48),c=getchar();
    12 }
    13 int gcd(int a,int b){return b?gcd(b,a%b):a;}
    14 int n,a0,a1,b0,b1,ans;
    15 int main(){
    16     read(n);
    17     for(re int i=1;i<=n;++i){
    18         read(a0);read(a1);read(b0);read(b1);
    19         int m=sqrt(b0+0.5); ans=0;
    20         for(re int j=1;j<=m;++j){//直接枚举约数
    21             if(b0%j) continue;
    22             int x=b1/b0*j;
    23             ans+=(gcd(x,b0)==j&&gcd(x,a0)==a1);
    24             if(j*j!=b0)
    25                 x=b1/j,ans+=(gcd(x,b0)==b0/j&&gcd(x,a0)==a1);
    26         }printf("%d
    ",ans);
    27     }return 0;
    28 }
    解法2
  • 相关阅读:
    CSS 兼容 总结
    IF IE
    取消chrome浏览器下input和textarea的默认样式
    左右浮动边距为0,中间间隔一定
    标题右边10px位置紧跟发布时间
    两款CSS3样式可视化在线生成工具
    文字截取,多余文字用省略号(...)代替
    O
    N
    M
  • 原文地址:https://www.cnblogs.com/kafuuchino/p/9876772.html
Copyright © 2011-2022 走看看