Aladdin and the Flying Carpet

本文介绍了一道有趣的数学题目,讲述了Aladdin如何利用不同尺寸的飞毯通过洞穴入口的故事。任务是找出给定面积和最小边长条件下可能存在的飞毯类型数量。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目:

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 bdenotes 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

题意:

给出a,b求区间[b,a]中a 的约数对数,  即(c,d),c*d=a并且c>=b,d>=b,   cd换位置是一对;

分析:

很显然用暴力枚举会超时,说到约数就想到因子个数,我先求出a的因子个数,两两一对会有因子个数/2 对,当然这个范围是[0,a],因此我们再想,题中给的是求[b,a]中的,如果b*b==a,那么很显然只有一对,因为大于b时一定会有两个数相乘小于a,也就是说除了这种特殊情况,小于b的因子的对应的约数对的因子一定是在大于b,这样我们只需将总的约数对数减去小于b的因子个数即可;

代码:

#include<stdio.h>
#include<math.h>
using namespace std;
#define maxn 1000010
typedef  long long ll;
ll prim[maxn],p[maxn];
int k=0;
int t;
ll a,b;
void primary()
{
    for(ll i=2;i<=maxn;i++)
    {
        if(!p[i])
        {
            prim[k++]=i;
            for(ll j=i*i;j<=maxn;j+=i)
                p[j]=1;
        }
    }
}
int countt()
{
    int s=1,tt=0,i=0;
    if(a==0)
        return 0;
    while(prim[i]<a&&i<k)
    {
        tt=0;
        while(a%prim[i]==0)
        {
            a/=prim[i];
            tt++;
        }
        s*=tt+1;
        i++;
    }
    if(a>1)
        s*=2;
    return s;
}
int main()
{
    ll i;
    int casee=0;
    primary();
    scanf("%d",&t);
    while(t--)
    {
         scanf("%lld %lld",&a,&b);
         int ans,cnt=0,num=0;
         if(b>=sqrt(a))//证明不存在两个数都大于b还相乘等于或者小于a;
                ans=0;
         else
         {
             for(i=1;i<b;i++)
             {
                 if(a%i==0)
                    cnt++;
             }
             num=countt()/2;
             ans=num-cnt;
         }
          printf("Case %d: %lld\n",++casee,ans);
    }
}
 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值