# lightoj 1341 算术基本定理

1341 - Aladdin and the Flying Carpet
 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.

# Output for Sample Input

2

10 2

12 2

Case 1: 1

Case 2: 2

#include<bitset>
#include<map>
#include<vector>
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<stack>
#include<queue>
#include<set>
#define inf 0x3f3f3f3f
#define mem(a,x) memset(a,x,sizeof(a))

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

inline ll in()
{
ll res=0;char c;
while((c=getchar())<'0' || c>'9');
while(c>='0' && c<='9')res=res*10+c-'0',c=getchar();
return res;
}
const int N=1000010;
int prime[79000];
bitset<N> vis;
int p;

void init()
{
for(int i=2;i<N;i++)
{
if(!vis[i])
{
prime[p++]=i;
for(int j=i+i;j<N;j+=i)
{
vis[j]=1;
}
}
}
}
int main()
{
int T=in();
int ii=1;
init();
while(T--)
{
ll area=in(),min_side=in();
if(min_side>=sqrt(area))
{
printf("Case %d: %d\n",ii++,0);
continue;
}
ll tmp=area;
int ans=1;
for(int i=0;i<p && 1LL*prime[i]*prime[i]<=area;i++)
{
int cnt=0;
while(area%prime[i] == 0)
{
area/=prime[i];
cnt++;
}
ans*=(cnt+1);
}
if(area!=1) ans<<=1;
ans>>=1;  //因数的个数除以二就是组数，同时排除了平方根
for(int i=1;i<min_side;i++) if(tmp%i==0) ans--; //min_side此时是小于sqrt（area）的
printf("Case %d: %d\n",ii++,ans);
}
return 0;
}


• 本文已收录于以下专栏：

举报原因： 您举报文章：lightoj 1341 算术基本定理 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)