我至今还不知道为什么
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);
}
}