Lightoj 1341 Aladdin and the Flying Carpet (unique decomposition theorem)

Source: Internet
Author: User





Aladdin and the Flying Carpet
PDF (中文版) Statistics Forum
Time Limit: 3 second (s) Memory Limit: 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 St Range Magicalflying carpet at the entrance. There were some strange creatures guarding theentrance of the cave. Aladdin could run, but he knew the there was a highchance of getting caught. So, he decided to use the magical flying carpet. Thecarpet was rectangular shaped and not square shaped. Aladdin took the carpetand with the help of it he passed the entrance.



Now all given the area of the carpet and the length ofthe minimum possible side of the carpet, your task was to find Ho W Many types ofcarpets is possible. For example, the area of the carpet, and the minimumpossible side of the carpet are 2, then there can be both types of CA Rpets Andtheir sides is: {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:ab (1≤b≤a≤1012) where adenotes the area of th E Carpet andb denotes the minimum possible sideof the carpet.


Output


For each case, print the case number and the number ofpossible carpets.


Sample Input Output for Sample Input

2

10 2

12 2

Case 1:1

Case 2:2




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




Title: To two number A, a, to satisfy C*d==a and c>=b and d>=b c,d two-tuple logarithm, (c,d) and (D,c) belong to the same situation






Title Analysis: According to the unique decomposition theorem, a unique decomposition, then the number of all positive numbers of a is num = (1 + A1) * (1 + a2) * ... (1 + AI), where the AI is the exponent of the element factor, see the unique decomposition theorem, because the topic says there will be no c==d, so num to remove 2, eliminate the repetition, and then enumerate the approximate number of a less than B, take Num to lose it.







#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#define ll long long
using namespace std;
int const MAX = 1e6 + 10;
int p[MAX];
bool u[MAX];
int num, cnt;
ll a, b, tmp;

void get_prime()  
{  
    memset(u, false, sizeof(u));
    for(int i = 2; i <= sqrt(MAX); i++)
        if(!u[i])
            for(int j = i * i; j <= MAX; j += i)
                u[j] = true;
    for(int i = 2; i <= MAX; i++)
        if(!u[i])
            p[cnt ++] = i;
}

void cal()
{
    for(int i = 0; i < cnt && p[i] <= sqrt(tmp); i++)
    {
        int cc = 0;
        while(tmp % p[i] == 0)
        {
            cc ++;
            tmp /= p[i];
        }
        num *= (cc + 1);

    }
    if(tmp > 1) //如果tmp不能被整分,说明还有一个素数是它的约数,此时cc=1
        num *= 2;
}

int main()
{
    int T;
    scanf("%d", &T);
    cnt = 0;
    get_prime();
    for(int ca = 1; ca <= T; ca++)
    {
        scanf("%lld %lld", &a, &b);
        if(a < b * b)
            printf("Case %d: 0\n", ca);
        else
        {
            num = 1;
            tmp = a;
            cal();
            num /= 2;
            for(int i = 1; i < b; i++)
                if(a % i == 0)
                    num --;
            printf("Case %d: %d\n", ca, num);
        }
    }
}









Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.



Lightoj 1341 Aladdin and the Flying Carpet (unique decomposition theorem)


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.