Time Limit: 3 second(s) | Memory Limit: 32 MB |
It's said that Aladdin had to solve seven mysteries beforegetting the Magical Lamp which summons a powerful Genie. Here we are concernedabout the first mystery.
Aladdin was about to enter to a magical cave, led by theevil sorcerer who disguised himself as Aladdin's uncle, found a strange magicalflying carpet at the entrance. There were some strange creatures guarding theentrance of the cave. Aladdin could run, but he knew that there was a highchance of getting caught. So, he decided to use the magical flying carpet. Thecarpet was rectangular shaped, but not square shaped. Aladdin took the carpetand with the help of it he passed the entrance.
Now you are given the area of the carpet and the length ofthe minimum possible side of the carpet, your task is to find how many types ofcarpets are possible. For example, the area of the carpet 12, and the minimumpossible side of the carpet is 2, then there can be two types of carpets andtheir 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: ab (1 ≤ b ≤ a ≤ 1012) where adenotes the area of the carpet and b denotes the minimum possible sideof the carpet.
Output
For each case, print the case number and the number ofpossible carpets.
Sample Input 2 10 2 12 2 Sample Output Case 1: 1 Case 2: 2
题意:给两个数m和n,求满足a*b=m(a>=n,b>=n,a>=b)的个数 根据唯一分解定理可以找到思路,先求出m所有因子的个数num,因为要满足a>=b,所以求出来的num/2,再减去比n小是m因子的个数即可
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<queue>
#include<cstring>
#include<string>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
#define for1(i,a) for(int (i)=1;(i)<=(a);(i)++)
#define for0(i,a) for(int (i)=0;(i)<(a);(i)++)
#define sf scanf
#define pf printf
#define mem(i,a) memset(i,a,sizeof i)
#define pi acos(-1.0)
#define eps 1e-10
const int Max=1e6+10;
int cou,a,b,p[Max],x;
bool vis[Max];
ll m,n,ans;
void prime()//素数打表
{
cou=0;
mem(vis,0);
for(int i=2;i<=Max;i++)
{
if(!vis[i])p[cou++]=i;
for(int j=0;j<cou&&i*p[j]<=Max;j++)
{
vis[i*p[j]]=1;
if(!(i%p[j]))break;
}
}
}
void fenjie()//唯一分解定理
{
ans=1;
ll h=m;
for(int i=0;i<cou&&(ll)p[i]*p[i]<=h;i++)
{
int num=0;
if(!(h%p[i]))
while(!(h%p[i]))
num++,h/=p[i];//素因式的个数
ans*=(num+1);
}
if(h>1)
ans*=2;
}
int main()
{
prime();
sf("%d",&x);
for1(i,x)
{
sf("%lld%lld",&m,&n);
if(m<n*n)
pf("Case %d: 0\n",i);
else
{
fenjie();
ans>>=1;
for(int i=1;i<n;i++)
if(!(m%i))//不满足a,b>=n的数
ans--;
pf("Case %d: %lld\n",i,ans);
}
}
return 0;
}