每日一题(01.16)

Description

给定两个大整数a和b,请你求a有多少个大于等于b的因子。

Input

第一行输入一个整数t(t<=4000),接下来的t行每行两个整数a,b(1<=b<=a<= 1 0 12 10^{12} 1012) 。

Output

a大于等于b的因子数。格式详见Sample。

Sample Input

2
10 2
12 2

Sample Output

Case 1: 1
Case 2: 2

Reference Code

#include <cstdio>
#include <cstring>
#define ll long long
using namespace std;
int const maxn=1e6+3;
bool np[maxn];
int p[maxn];
int res,primes=0;
int main(){
    memset(np,false,sizeof(np));
    for(int i=2;i*i<=maxn;i++) if(!np[i])
        for(int j=i*i;j<=maxn;j+=i)
            np[j]=true;
    for(int i=2;i<=maxn;i++)
        if(!np[i]) p[primes++]=i;
    int t;
    scanf("%d",&t);
    ll a,b,buf;
    for(int cnt=1;cnt<=t;cnt++){
        scanf("%lld%lld",&a,&b);
        if(a<b*b) printf("Case %d: 0\n",cnt);
        else{
            res=1,buf=a;
            for(int i=0;i<primes&&p[i]*p[i]<=buf;i++){
                int sum=1;
                while(buf%p[i]==0){
                    sum++;
                    buf/=p[i];
                }
                res*=sum;
            }
            if(buf>1) res<<=1;
            res>>=1;
            for(int i=1;i<b;i++) if(!(a%i)) res--;
            printf("Case %d: %d\n",cnt,res);
        }
    }
}

/*暴力法,会超时
#include <cstdio>
#include <cmath>
#define ll long long
int main(){
    int t,res;
    ll a,b,high;
    scanf("%d",&t);
    for(int cnt=1;cnt<=t;cnt++){
        res=0;
        scanf("%lld%lld",&a,&b);
        high=sqrt(a);
        for (ll i=b;i<=high;i++){
            if (!(a%i)) res+=1;
        }
        printf("Case %d: %d\n",cnt,res);
    }
}
*/
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值