【数论】Aladdin and the Flying Carpet

我至今还不知道为什么

for(int i=b;i<=sqrt(a);i++)

的直接暴力会超时

for(int i=1;i<b;i++)

的委婉暴力不会

算数基本定理:http://blog.csdn.net/u012860063/article/details/44784031
也是这道题的题解

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 1000007;

int T;
LL a, b;
int isp[maxn],p[maxn];
int tot = 0;

void find(){
    for(int i=2;i<maxn;i++) isp[i] = 1;
    for(int i=2;i<maxn;i++){
        if(isp[i]) p[tot++] = i;
        for(int j=0;j<tot && i*p[j]<maxn;j++){
            isp[i*p[j]] = 0;
            if(i%p[j] == 0) break;
        }
    }
} 

LL count(LL x){
    if(x <= 1) return x;
    LL res = 1;

    for(int i=0;i<tot && p[i]<x;i++){
        LL num = 0;
        while(x%p[i] == 0) {
            x/=p[i];
            num++;
        }
        res*=(1+num);
    }
    if(x>1) res*=2;
    return res;
}

int main(){
    find();
    cin >> T;
    int cas = 1;
    while (T--){
        scanf("%lld%lld", &a, &b);
        LL ans = 0;
        if(b>=sqrt(a)) {
            printf("Case %d: %lld\n", cas++,0);
            continue;
        }
        ans = count(a)/2;
        for(LL i=1;i<b;i++) {
            if(a%i == 0) ans--;
        }
        printf("Case %d: %lld\n", cas++, ans);
    }
}
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值