LightOJ 1341

题意 :

一个数可以表示 N 对 数相乘(x1,x2)

输入另一个数b  求有多少对x1 x2 俊大于等于 b


求标准分解式的指数  因子数为 II(ai + 1)(表示不出数学符号.............)

代码:

#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
using namespace std;
typedef long long LL;
const int maxn = 1e6 +131;
int vis[maxn];
LL Primes[maxn];
int Count,ans;
LL a,b;
void INT() { //质数表  
	Count = 0;
	for(int i = 2; i <= maxn; ++i) 
	{
		if(!vis[i]) {
			Primes[Count++] = i;
			for(int j = i; j <= maxn; j+= i) 
			vis[j] = 1;
		}
	}
}

void DFS(LL dep, LL x) { //构造解答树,求出小于b的有多少个a 的因数 
	ans--;
	for(int i = dep; i < Count; ++i) 
	{
		if(x * Primes[i] < b) 
		{
			if( a  % (x* Primes[i]) == 0) 
			DFS(i,x*Primes[i]);
		}
		else return ;
	}
}

int main() {
	INT();
	int T;
	scanf("%d",&T);
	for(int kase = 1; kase <= T; ++kase) {
		scanf("%lld%lld",&a,&b) ;
		if(b*b >= a) {
			printf("Case %d: 0\n",kase);
			continue;
		}
		ans = 1;
		LL tmp = a;
		for(int i = 0; i < Count && Primes[i] * Primes[i] <= tmp; ++i ) {
			if(tmp % Primes[i] == 0) {
				LL tot = 0;
				while(tmp % Primes[i] == 0) {
					tot++;
					tmp /= Primes[i];
				}
				ans *= (tot+1);
			} 
		}
		
		if(tmp > 1) ans <<= 1; //如果还有剩余的质数,则因子数还要 * 2 
		ans >>= 1;//求有多少对
		DFS(0,1); if(b == 1) ans ++;
		printf("Case %d: %lld\n",kase, ans);
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值