Aladdin and the Flying Carpet LightOJ

质因数分解

求出[1,a] 的和 减去[1,b] 的和

#include<bits/stdc++.h>
using namespace std;
#define fst first
#define sec second
#define sci(num) scanf("%d",&num)
#define scl(num) scanf("%lld",&num)
#define mem(a,b) memset(a,b,sizeof a)
#define cpy(a,b) memcopy(a,b,sizeof b)
typedef long long LL;
typedef pair<int,int> P;
const int MAX_N = 510;
const int MAX_M = 10000;
const int MAX_P = 1e6 + 100;
bool notprime[MAX_P];
int primes[MAX_P],cnt;
void init() {
    cnt = 0;
    for (int i =2 ;i < MAX_P;i++) {
        if (!notprime[i]) {
            primes[cnt++] = i;
            for (int j = i + i;j < MAX_P;j += i) {
                notprime[j] = true;
            }
        }
    }
}
LL cond(LL a) {
    LL cp = 1;
    for (int i = 0;i < cnt && primes[i] < a;i++) {
        if (a % primes[i] == 0) {
            int loc = 0;
            while (a % primes[i] == 0 && a != 1) {
                a = a / primes[i];
                loc++;
            }
            cp *= (1 + loc);
        }
    }
    if (a > 1) cp *= 2;
    return cp;
}
int main() {
    init();
    int T;sci(T);
    for (int cs = 1;cs <= T;cs++) {
        LL a,b;
        scl(a); scl(b);
        LL ans = 0;
        if (b * b < a) {
            int c2 = 0;
            for (LL i = 1;i < b;i++) {
                if ( a % i == 0) c2++;
            }
            ans = cond(a) / 2- c2;
        }
        printf("Case %d: %lld\n",cs,ans);
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值