2 条题解

  • 0
    @ 2026-9-2 9:57:18
    • LaTex写公式有点麻烦,所以我用以前写好的代替了

    • 想看原版可以戳这里

    • 首先来分析一下这个题目

    证明:

    • 把上面的结论推广一下,得到结论PP

    对于两个正整数a,ba,b,设gcd(a,b)=kgcd(a,b)=k,则存在gcd(a/k,b/k)=1gcd(a/k,b/k)=1

    • 应用结论PP

    • 整理一下式子

    用心体会这两个式子,你会发现xxa1a_1的整数倍而且是b1b_1的因子

    ~~好像这个由gcd和lcm也可以得到?~~嗯,就这样

    于是得到一种解题思路

    b1\sqrt b_1枚举b1b_1的因子(也就是xx),如果这个数是a1a_1的整数倍并且满足那两个式子,则ans++ans++

    • code
    #include<cstdio>
    using namespace std;
    int gcd(int a,int b) {
        return b==0?a:gcd(b,a%b);
    }
    int main() {
        int T;
        scanf("%d",&T);
        while(T--) {
            int a0,a1,b0,b1;
            scanf("%d%d%d%d",&a0,&a1,&b0,&b1);
            int p=a0/a1,q=b1/b0,ans=0;
            for(int x=1;x*x<=b1;x++) 
                if(b1%x==0){
                    if(x%a1==0&&gcd(x/a1,p)==1&&gcd(q,b1/x)==1) ans++;
                    int y=b1/x;//得到另一个因子
                    if(x==y) continue; 
                    if(y%a1==0&&gcd(y/a1,p)==1&&gcd(q,b1/y)==1) ans++;
                }
            printf("%d\n",ans);
        }
        return 0;
    }
    
    • 0
      @ 2025-10-8 16:53:02
      #include<bits/stdc++.h>
      using namespace std;
      typedef long long LL;
      LL gcd(LL a, LL b){return (b==0) ? a : gcd(b, a%b);}
      LL lcm(LL a, LL b){ return a*b/gcd(a, b);}
      int main()
      {
          int n;scanf("%d", &n);
          while(n--)
          {
              LL a0, a1, b0, b1;
              scanf("%lld%lld%lld%lld", &a0, &a1, &b0, &b1);
              
              int ans=0;
              for(LL i=1; i*i <= b1; i++)if(b1%i == 0)
              {
                  if(gcd(i, a0) == a1 && lcm(i, b0) == b1) ans++;
                  int j = b1/i;
                  if(i == j) continue;
                  if(gcd(j, a0) == a1 && lcm(j, b0) == b1) ans++;
              }
              printf("%d\n", ans);
          }
          return 0;
      }
      
      • 1

      [NOIP 2009 提高组] Hankson 的趣味题

      信息

      ID
      735
      时间
      1000ms
      内存
      128MiB
      难度
      7
      标签
      递交数
      175
      已通过
      45
      上传者