LightOJ - 1341 Aladdin and the Flying Carpet (算术基本定理)

题意:

就是。。。。求a的所有大于b的因子有多少对

算术基本定理求 所有因子 阿欧。。。偷张图。

注意范围 就好  。。。。。

解析:

在1 -1012的范围内求大于b的所有a的因子的对数(有几对)

就等于 在1 -1012的范围内求出a的所有因子 除二  减去  在1 - (b-1)的范围内a的所有因子

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
#include<cmath>
#include<map>
#include<stack>
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long LL;
const int maxn=1000010;

LL primes[maxn], vis[maxn];
LL base[maxn], mi[maxn];
int ans = 0;
void init()
{
    mem(vis,0);
    for(int i=2; i<maxn; i++)
        if(!vis[i])
        {
            primes[ans++] = i;
            for(LL j=(LL)i*i; j<maxn; j+=i)
                vis[j] = 1;
        }
}

int main()
{
    int T;
    init();
    int m = 0;
    scanf("%d",&T);
    while(T--)
    {
        LL S, edge;
        scanf("%lld%lld",&S,&edge);
        LL x = S;
        if(edge * edge >= S){
            printf("Case %d: 0\n",++m); continue;
        }
        LL res = 1, cnt2 = 0;
        for(int i=0; i < ans && primes[i] * primes[i] <= S; i++)
        {
            LL cnt = 0;
            while(S % primes[i] == 0)
            {
                cnt++;
                S /= primes[i];

            }
            if(S > 0){
                base[cnt2] = primes[i];
                mi[cnt2++] = cnt;
            }
        }
        if(S > 1)
        {
            base[cnt2] = S;
            mi[cnt2++] = 1;
        }
        LL temp = 1;
        for(int i=0; i<cnt2; i++)
        {
            res *= (mi[i]+1);
            if(base[i] < edge)
                temp *= mi[i];

        }
        printf("Case %d: %lld\n",++m,res/2 - temp);

    }

    return 0;
}

猜你喜欢

转载自www.cnblogs.com/WTSRUVF/p/9178289.html
今日推荐