E - Aladdin and the Flying Carpet
阅读原文时间:2023年07月08日阅读:2

It's said that Aladdin had to solve seven mysteries before getting the Magical Lamp which summons a powerful Genie. Here we are concerned about the first mystery.

Aladdin was about to enter to a magical cave, led by the evil sorcerer who disguised himself as Aladdin's uncle, found a strange magical flying carpet at the entrance. There were some strange creatures guarding the entrance of the cave. Aladdin could run, but he knew that there was a high chance of getting caught. So, he decided to use the magical flying carpet. The carpet was rectangular shaped, but not square shaped. Aladdin took the carpet and with the help of it he passed the entrance.

Now you are given the area of the carpet and the length of the minimum possible side of the carpet, your task is to find how many types of carpets are possible. For example, the area of the carpet 12, and the minimum possible side of the carpet is 2, then there can be two types of carpets and their sides are: {2, 6} and {3, 4}.

Input

Input starts with an integer T (≤ 4000), denoting the number of test cases.

Each case starts with a line containing two integers: a b (1 ≤ b ≤ a ≤ 1012) where a denotes the area of the carpet and b denotes the minimum possible side of the carpet.

Output

For each case, print the case number and the number of possible carpets.

Sample Input

2

10 2

12 2

Sample Output

Case 1: 1

Case 2: 2

题目大意 就是给你一个面积N和一个可能的最小边m,问你满足条件的组合有多少个(不能是正方形)

题解:先求出a的因子的个数,然后暴力求出小与b而且是a的因子的个数,然后再减去就行了。对于这个题,边的最小值为b,所以如果b*b>=a的话,那么一定无解。若有解那么b<=sqrt(a)所以b的范围要小于1e6,但是t的范围是4e3,时间复杂度大约是o(bt)=4e10。明显不行…..,但是百度上都这么做的,可能是数据有点水吧~。

using namespace std;
typedef long long ll;
const ll N=1e6+;
const ll MAX=1e6+;
bool primes[N];
ll pre[N];
ll pos=;
void inint(){
primes[]=;
primes[]=;
for(ll i=;i<=MAX;i++){ if(!primes[i]) pre[++pos]=i; for(ll j=;j<=pos&&i*pre[j]<=MAX;j++){ primes[i*pre[j]]=; if(i%pre[j]==) break; } } } void solve(ll time){ ll a,b; scanf("%lld%lld",&a,&b); ll m=a; if(b*b>=a) {
printf("Case %d: 0\n",time);
return ;
}
ll ans=;
for(ll i=;i<=pos;i++){ if(pre[i]>a) break;
if(a%pre[i]==){
ll p=;
while(a%pre[i]==) {
a/=pre[i];p++;
}
ans*=((ll)+p);
}
}
if(a!=) ans*=(ll);
ans/=(ll);
for(ll i=;i<b;i++) if(m%i==) ans--;
printf("Case %d: %lld\n",time,ans);
}
int main(){
int t;
inint();
scanf("%d",&t);
for(int i=;i<=t;i++) solve(i);
return ;
}

手机扫一扫

移动阅读更方便

阿里云服务器
腾讯云服务器
七牛云服务器

你可能感兴趣的文章