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

题目链接:qaq

 

题意:找出符合的因子对数的个数

 

思路:知道算数基本定理后就简单了(感觉和暴力的复杂度一样啊QAQ。。难受)

 

附上代码:

#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<algorithm>
using namespace std;
const int MAXN = 1000100;
int prime[MAXN + 1];
long long sum=1;
void getPrime() {
	memset(prime, 0, sizeof(prime));
	for (int i = 2; i <= MAXN; i++) {
		if (!prime[i])prime[++prime[0]] = i;
		for (int j = 1; j <= prime[0] && prime[j] <= MAXN / i; j++) {
			prime[prime[j] * i] = 1;
			if (i%prime[j] == 0) break;
		}
	}
}
long long factor[100][2];
int fatCnt;
void getFactors(long long x) {
	fatCnt = 0;
	long long tot=0;
	long long tmp = x;
	for (int i = 1; prime[i] <= tmp / prime[i]; i++) {
		factor[fatCnt][1] = 0;
		tot=0;
		if (tmp%prime[i] == 0) {
			factor[fatCnt][0] = prime[i];
			while (tmp%prime[i] == 0) {
				factor[fatCnt][1]++;
				tmp /= prime[i];
				tot++;
			}
			sum*=(tot+1);
			fatCnt++;
		}
	}
	if (tmp != 1) {
		factor[fatCnt][0] = tmp;
		factor[fatCnt++][1] = 1;
		sum*=2;
	}
}
int main (void){
    int t;
    scanf("%d",&t);
    int ca=1;
    getPrime();
    while(t--){
        sum=1;
        long long n,m;
        scanf("%lld%lld",&n,&m);
        printf("Case %d: ",ca++);
        if(m>sqrt(n)){
            printf("0\n");
            continue;
        }
        getFactors(n);
    //printf("%d\n",sum);
        sum=sum/2;
        for(int i=1;i<m;i++){
            if(n%i==0) sum--;
        }
        printf("%lld\n",sum);
    }
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值