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}.
InputInput 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.
OutputFor each case, print the case number and the number of possible carpets.
Sample Input2
10 2
12 2
Sample OutputCase 1: 1
Case 2: 2
#include<cmath>
#include<cstdio>
#include<cstring>
using namespace std;
const int MAXN = 1000010;
long long int a,b;
int prime[MAXN + 1];
int ans;
void getPrime()
{
memset(prime, 0, sizeof(prime));
for (int i = 2; i <= MAXN; i++)
{
if (!prime[i])
{
prime[++prime[0]] = i;
}
for (int j = 1; j <= prime[0] && prime[j] <= MAXN / i; j++)
{
prime[prime[j] * i] = 1;
if (i % prime[j] == 0)
{
break;
}
}
}
return ;
}
long long factor[100][2];
int fatCnt;
void getFactors(long long x)
{
fatCnt = 0;
ans=1;
if(a/b<b)
{
ans = 0;
return ;
}
long long tmp = x;
for (int i = 1; prime[i] <= tmp / prime[i]; i++)
{
int t=0;
if (tmp % prime[i] == 0)
{
while (tmp % prime[i] == 0)
{
t++;
tmp /= prime[i];
}
ans*=(t+1);
}
}
if (tmp != 1)
{
ans*=2;
}
ans/=2;
for(long long int l=1;l<b;l++)
{
if(a%l==0)
ans--;
}
}
int main()
{
int n;
scanf("%d",&n);
getPrime();
for(int i=1;i<=n;i++)
{
scanf("%lld%lld",&a,&b);
getFactors(a);
printf("Case %d: %d\n",i,ans);
}
return 0;
}

本文介绍了一道关于Aladdin使用矩形飞毯通过洞穴入口的算法题,题目要求计算在给定面积和最小边长的情况下,可能存在的不同尺寸飞毯的数量。文章提供了完整的代码实现,并利用算数基本定理进行解答。
682

被折叠的 条评论
为什么被折叠?



