首页 > 代码库 > LightOJ 1341 - Aladdin and the Flying Carpet 基本因子分解

LightOJ 1341 - Aladdin and the Flying Carpet 基本因子分解

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

 

题意:给你长方形的面积a,边最小为b,问有几种情况。

思路:对a进行素因子分解,再乘法原理算一下,最后减去小于b的因子的情况即可。

 

/** @Date    : 2016-12-01-19.04  * @Author  : Lweleth (SoungEarlf@gmail.com)  * @Link    : https://github.com/  * @Version :  */#include<bits/stdc++.h>#define LL long long#define PII pair<int ,int>#define MP(x, y) make_pair((x),(y))#define fi first#define se second#define PB(x) push_back((x))#define MMG(x) memset((x), -1,sizeof(x))#define MMF(x) memset((x),0,sizeof(x))#define MMI(x) memset((x), INF, sizeof(x))using namespace std;const int INF = 0x3f3f3f3f;const int N = 1e6+20;LL pri[N];int c = 0;bool vis[N];void prime(){    for(int i = 2; i <= N; i++)    {        if(!vis[i])        {            for(int j = i + i; j <= N; j+= i)            {                if(!vis[j])                    vis[j] = 1;            }            pri[c++] = i;        }    }}int main(){    prime();    int T;    int cnt = 0;    cin >> T;    while(T--)    {        LL a , b;        scanf("%lld%lld", &a, &b);        LL t = a;        LL ans = 1;        LL cc = 0;        if(b > sqrt(a))        {            printf("Case %d: 0\n", ++cnt);            continue;        }        for(int i = 0; i < c && pri[i]*pri[i] <= t; i++)        {            LL cc = 0;            while(t % pri[i] == 0)            {                cc++;                t /= pri[i];            }            ans *= cc + 1;        }        if(t > 1)            ans *= 2;        ans /= 2;        for(int i = 1; i < b; i++)            if(a % i == 0)            {                ans--;            }        printf("Case %d: %lld\n", ++cnt, ans);    }    return 0;}

LightOJ 1341 - Aladdin and the Flying Carpet 基本因子分解