数论 light 1341

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

题目链接:http://lightoj.com/login_main.php?url=volume_showproblem.php?problem=1341

题意:给出一个矩形面积a和一个边长b,要求求出符合面积是a,且一条边是b, 一条比b大的这样子的矩阵的个数。

n = p1^a1 * p2^a2*…*pm^am,(pi是素数) n 的因数的个数: num = (a1+1)*(a2+1)…(am+1);

 #include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
using namespace std;

typedef long long ll;
ll n, m, cnt;
const int maxn = 1e6+5;
ll vis[maxn];
ll prime[maxn];

void get_prime()
{
    memset(vis, 0, sizeof vis);
    vis[1] = 1;
    memset(prime, 0, sizeof prime);
    cnt = 0;
    for (ll i = 2; i < maxn; i++)
    {
        if (!vis[i])
        {
            prime[++cnt] = i;
            for (ll j = i*i; j < maxn; j+=i)
                vis[j] = 1;
        }        
    }
    //cout << cnt << endl;
    //cout << prime[cnt];
    //for(int i = cnt-100; i <= cnt; i ++)
    //    cout << prime[i] << endl;
}

ll solve()
{
    ll ans = 1;
    ll tmp = n;
    if(n <= m*m) 
        return 0;
    for(int i = 1; prime[i]*prime[i]<= tmp && i<=cnt; i++)
    {
        int c = 0;
        while(tmp%prime[i] == 0)
        {
            c++;
            tmp /= prime[i];
        }
        ans *= (c+1); 
    }
    if(tmp > 1)
        ans *= 2;
    ans /= 2;
    for(int i = 1; i < m; i++)
        if(n%i == 0)
            ans--;
    return ans;
}

int main()
{
    ios::sync_with_stdio(false);
    get_prime();
    int t;
    cin >> t;
    int cas = 1;
    while(t --)
    {
        cin >> n >> m;
        printf("Case %d: %lld\n", cas++, solve());
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_38295645/article/details/81285625