Educational Codeforces Round 106 D.The Number of Pairs

D. The Number of Pairs

题目传送门:

D. The Number of Pairs

题目大意:

给你三 个数c,d,x,要你找到有多少对数满足 c * lcm(a,b) - d * gcd(a,b) = x

思路:

在这里插入图片描述
转自大佬的博客

AC Code

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=2e7+10;
int primes[N],ans[N],cnt;
int p[N];
LL res=0;
LL quick_pow(LL a,LL b)
{
    LL ans=1;
    while(b)
    {
        if(b%2) ans=ans*a;
        a=a*a;
        b=b/2;
    }
    return ans;
}
void solve(int x)
{
    res+=quick_pow(2,p[x]);
}
int main()
{
    int t;
    scanf("%d",&t);
    for(int i=2;i<N;i++)
    {
        if(ans[i]==0)
        {
            primes[++cnt]=i;
            p[i]=1;
        } 
        for(int j=1;j<=cnt&&primes[j]*i<N;j++)
        {
            ans[primes[j]*i]=1;
            if(i%primes[j]==0)
            {
                p[primes[j]*i]=p[i];
                break;
            } 
            else p[primes[j]*i]=p[i]+1;
        }
    }
    while(t--)
    {
        LL c,d,x;
        scanf("%lld%lld%lld",&c,&d,&x);
        res=0;
        for(LL i=1;i<=sqrt(x);i++)
        {
            if(x%i) continue;
            if((i+d)%c==0) solve((i+d)/c);
            if((x/i+d)%c==0&&i!=x/i) solve((x/i+d)/c);
        }
        printf("%lld\n",res);
    }
    //system("pause");
    return 0;
}

感觉这种题目充满了套路但是又不乏思维,数学的题目还是练的太少了。这题也顺便也让我学会了n个数如何快速求得每个数可以分解为多少个不同的质因子。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值