唯一分解定理(数论)

数论

唯一分解定理

(1)一个大于1的正整数N, 如果它的标准分解式为:
在这里插入图片描述
那么它的正因数个数为:在这里插入图片描述
(2)它的全体正因数之和为:在这里插入图片描述

Aladdin and the Flying Carpet

给一对数字 a,b ,a是一个长方形的面积,问有多少种整数的边的组合可以组成面积为a的长方形,要求最短的边不得小于b

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

#include<bits/stdc++.h>

#define ll long long
using namespace std;
const int N = 1e6 + 10;
int primes[N], cnt;
bool st[N];
ll num, tmp;

void get_primes()
{
    for(int i = 2; i <= 1000010; i ++)
    {
        if(!st[i]) primes[cnt ++] = i;
        for (int j = 0; primes[j] <= 1000010 / i; j++) {
            st[primes[j] * i] = true;
            if(i % primes[j] == 0) break;
        }
    }
}

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

int main()
{
    int t;
    scanf("%d", &t);
    int Case = 0;
    get_primes();
    while(t --){
        ll n, m;
        scanf("%lld%lld", &n, &m);
        if(n < m * m) printf("Case %d: 0\n", ++Case);
        else{
            num = 1;
            tmp = n;
            cal();
            num /= 2;
            for(int  i = 1; i < m; i ++)
                if(n % i == 0)
                num --;
        printf("Case %d: %d\n", ++Case, num);
        }
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值