Lightoj 1341-aladdin and the Flying Carpet (arithmetic basic theorem AH)

Source: Internet
Author: User

Title Link: http://lightoj.com/volume_showproblem.php?problem=1341



It's said that Aladdin had to solve seven mysteries before getting the magical Lamp which summons a powerful Genie. Here we is 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 s Trange 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 is a high chance of getting caught. So, he decided to use the magical flying carpet. The carpet was rectangular shaped and not square shaped. Aladdin took the carpet and with the help of it he passed the entrance.

Now all given the area of the carpet and the length of the minimum possible side of the carpet, your task was to find H OW many types of carpets is possible. For example, the area of the carpet, and the minimum possible side of the carpet are 2, then there can are both types of C Arpets and their sides are: {2, 6} and {3, 4}.

Input

Input starts with an integer T (≤4000), denoting the number of test cases.

Starts with a line containing-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 Output for Sample Input

2

10 2

12 2

Case 1:1

Case 2:2



Test Instructions :

Given the integers a and B, the number of approximate pairs of a in the interval [B, a], the approximate pairs of a (e.g. [2, 3] and [3, 2] are the same pair).

Ps:

The first prime is a table, and then the basic theorem of arithmetic is used

(1) A positive integer greater than 1 N, if its standard decomposition is:, then it is a number of positive.

Can find the number of positive factors, and then divided by 2, is the logarithm, and finally the violence to solve the [1,b] A of the number of positive, subtraction is the answer!

The code is as follows:

#include <cstdio> #include <cstring> #include <cmath> #include <iostream> #include < algorithm>using namespace std; #define MAXN 1000047#define LL long longll prim[maxn], p[maxn];int k = 0;void Find_prim ()    {k = 0;            for (LL i = 2; I <= maxn; i++) {if (!p[i]) {prim[k++] = i;            for (LL j = i+i; J <= Maxn; j+=i) {p[j] = 1;    }}}}ll cont (ll a) {ll s = 1;    if (a = = 0) {return 0;    } LL tt = 0;    LL i = 0;        while (Prim[i] < a && i < k) {tt = 0;                if (a%prim[i] = = 0) {while (a%prim[i] = = 0) {A/=prim[i];            tt++;        }} s *= tt+1;    i++; } if (a > 1) {s *= 1+1;//once} return s;}    int main () {LL A, B;    int t;    int cas = 0;    Find_prim ();    scanf ("%d", &t); while (t--) {scanf ("%lld%lld", &a,&b);        int cnt = 0;        LL num = 0, ans;        if (b >= sqrt (a)) ans = 0;  B Size Qualification else {for (LL i = 1; i < b; i++)//Violent enumeration [1, b] in the approximate {if (a%i                = = 0) {cnt++;            }} num = Cont (a)/2;        ans = num-cnt;    } printf ("Case%d:%lld\n", ++cas,ans); } return 0;}



Lightoj 1341-aladdin and the Flying Carpet (arithmetic basic theorem AH)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.