P1072 Hankson 的趣味題

來源:互聯網
上載者:User

標籤:原理   problem   for   names   col   getch   gcd   lcm   www.   

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\n",ans);27     }return 0;28 }
解法2

 

P1072 Hankson 的趣味題

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.