Light OJ 1341 Aladdin and the Flying Carpet

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 integerT (≤ 4000), denoting the number of test cases.

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

Output

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

Sample InputOutput for Sample Input

2

10 2

12 2

Case 1: 1

Case 2: 2

唯一分解定律的应用:

求a的大于等于b的约数个数。先求出总的约数个数,然后剔除小于b的即可。

考虑每个素因数都有bi个,那么有(bi+1)种选择。

#include<cstdio>#include<cstring>#include<algorithm>#include<vector>#include<string>#include<iostream>#include<queue>#include<cmath>#include<map>#include<stack>#include<bitset>using namespace std;#define REPF( i , a , b ) for ( int i = a ; i <= b ; ++ i )#define REP( i , n ) for ( int i = 0 ; i < n ; ++ i )#define CLEAR( a , x ) memset ( a , x , sizeof a )typedef long long LL;typedef pair<int,int>pil;const int INF = 0x3f3f3f3f;const int maxn=1e6+5;bool vis[maxn+10];int prim[maxn/10];LL a,b;int t,cnt=0;void init(){int m=sqrt(maxn+0.5);for(int i=2;i*i<=maxn;i++)if(!vis[i])for(int j=i*i;j<=maxn;j+=i) vis[j]=1;for(int i=2;i<=maxn;i++)if(!vis[i]) prim[cnt++]=i;}LL solve(){LL ans=1,temp=a;if(a/b<b) return 0;for(int i=0;i<cnt&&prim[i]*prim[i]<=a;i++){int c=0;while(a%prim[i]==0){c++;a/=prim[i];}ans*=(c+1);}if(a>1) ans<<=1;ans>>=1;//有重复for(int i=1;i<b;i++)if(temp%i==0) ans–;return ans;}int main(){int cas=1;init();cin>>t;while(t–){cin>>a>>b;cout<<"Case "<<cas++<<": "<<solve()<<endl;}return 0;}Light OJ 1236:

Find the result of the following code:

longlongpairsFormLCM(intn){ longlongres=0; i<=n;i++) for(intj=i;j<=n;j++) if( lcm(i,j) ==n ) res++;// lcm means least common multiple returnres;}

A straight forward implementation of the code may time out. If you analyze the code, you will find that the code actually counts the number of pairs(i, j)for whichlcm(i, j) = nand(i ≤ j).

Input

Input starts with an integerT (≤ 200), denoting the number of test cases.

Each case starts with a line containing an integern (1 ≤ n ≤ 1014).

Output

For each case, print the case number and the value returned by the function’pairsFormLCM(n)’.

Sample InputOutput for Sample Input

15

2

3

4

6

8

10

12

15

18

20

21

24

25

27

29

Case 1: 2

Case 2: 2

Case 3: 3

Case 4: 5

Case 5: 4

Case 6: 5

Case 7: 8

Case 8: 5

Case 9: 8

Case 10: 8

Case 11: 5

Case 12: 11

Case 13: 3

Case 14: 4

Case 15: 2

求LCM(i,j)(i<=j)为n的对数:求素数分解式,若bi是第i个素数的幂,,那么对于这两个数

人要想成为生活的主人,不仅要适应生活,而且还要发挥主动性,

Light OJ 1341 Aladdin and the Flying Carpet

相关文章:

你感兴趣的文章:

标签云: