LightOJ-1341-Aladdin and the Flying Carpet - unique prime decomposition theorem Screening +

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 b denotes 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


The meaning of problems: given a and b, determine the number of required multiplication of two numbers is equal to a, and the two numbers must be> = b

Ideas: the use of a unique decomposition theorem, the number of factors determine how many, then the number of factor / 2 is a logarithmic factor, minus can not meet the condition (the condition is not satisfied: there is a factor less than number b)


Unique Factorization Theorem: N = p1 ^ a1 * p2 ^ a2 * p3 ^ a3 * ... * pn ^ an (wherein p1, p2, ... pn factor of N, a1, a2, ..., an are exponential factor)

The number N of seek factor: sum = (1 + a1) * (1 + a2) * (1 + a3) * ... * (1 + an)

 

 1 #include<stdio.h>
 2 #include<cmath>
 3 #include<string.h>
 4 typedef long long ll;
 5 using namespace std;
 6 
 7 
 8 const int N=1e6+20;
 9 int book[N],p;
10 ll pri[N];
11 
12 void prime()
13 {
14     //非素数标记为1
15     memset(book,0,sizeof(book));
16     book[0]=1;
17     book[1]=1;
18     p=0;
19     for(int i=2; i<N; i++)
20     {
21         if(book[i]==0)
22         {
23             pri[p++]=i;
24             for(int j=i*2; j<N; j+=i)
25                 book[j]=1;
26         }
27     }
28 }
29 
30 ll yinzi(ll a)//求N的因子个数sum=(1 + a1)*(1 + a2)*(1 + a3)*...*(1 + an);
31 {
32     ll ans=0,sum=1;
33     for(ll i=0; i<p&&(pri[i]*pri[i]<=a); i++)
34     {
35         if(a%pri[i]==0)
36         {
37             ans=0;
38             while(a%pri[i]==0)
39             {
40                 ans++;
41                 A / = PRI [I];
 42 is              }
 43 is              SUM * = ( . 1 + ANS);
 44 is          }
 45      }
 46 is      IF (A> . 1 ) // Description left has a prime factor is not counted, can be obtained according to the formula 
47          * SUM = SUM ( . 1 + . 1 );
 48      return SUM;
 49  }
 50  
51 is  int main ()
 52 is  {
 53 is      Prime ();
 54 is      int T;
 55      LL A, B;
 56 is      Scanf ( "%d",&t);
57     int tt=1;
58     while(t--)
59     {
60         scanf("%lld %lld",&a,&b);
61         if(a<b*b)
62         {
63             printf("Case %d: 0\n",tt++);
64             continue;
65         }
66         else
67         {
68             ll ans=yinzi(a);
69             ll duishu=ans/2;
70             for(ll i=1; i<b; i++)
71             {
72                 if(a%i==0)
73                 {
74                     duishu--;
75                 }
76             }
77             printf("Case %d: %lld\n",tt++,duishu);
78         }
79     }
80     return 0;
81 }

 

Guess you like

Origin www.cnblogs.com/OFSHK/p/11329177.html