P1072 [NOIP2009 提高组] Hankson 的趣味题

Rose

$O(sqrt n)$也是可以接受的对吧

化简式子得$gcd(frac{x}{a_1},frac{a_o}{a_1})=1$和$gcd(frac{b_1}{x},frac{b_1}{b_0})=1$

然后枚举$b_1$的因子就可以了

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int t;
int a0,a1,b0,b1;
int gcd(int x,int y){
    if(y==0){
        return x;
    }
    return gcd(y,x%y);
}
int main(){
    scanf("%d",&t);
    while(t--){
        scanf("%d%d%d%d",&a0,&a1,&b0,&b1);
        int cnt=0;
        for(int i=1;i*i<=b1;++i){
            if(b1%i==0){
                if(i%a1==0&&gcd(i/a1,a0/a1)==1&&gcd(b1/i,b1/b0)==1){
                    cnt++;
                }
                int y=b1/i;
                if(y==i) continue;
                if(y%a1==0&&gcd(y/a1,a0/a1)==1&&gcd(b1/y,b1/b0)==1){
                    cnt++;
                }   
            }
        }
        cout<<cnt<<endl;
    }
    return 0;
}
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇