POINT:
要求所有的元素都不是正整数N的因数。
那么求这个数 存在因素在集合中。用容斥做。
然后减掉即可。
wa点,会爆LL。
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <string>
#include <map>
using namespace std;
#define LL unsigned long long
const int maxn = 1e2+3;
LL l,r,k;
LL a[maxn];
LL sum=0;
void dfs(LL x,LL now,LL c)
{
if(x>r) return;//x会爆LL
if(c&1){
sum+=r/x-(l-1)/x;
}else{
sum-=r/x-(l-1)/x;
}
for(LL i=now+1;i<=k;i++){
dfs(x*a[i],i,c+1);
}
}
int main()
{
while(~scanf("%llu%llu%llu",&l,&r,&k)){
sum=0;
for(LL i=1;i<=k;i++)
scanf("%llu",&a[i]);
for(LL i=1;i<=k;i++)
dfs(a[i],i,1);
printf("%llu\n",(r-l+1)-sum);
}
}

本文介绍了一个利用容斥原理解决特定数学问题的方法。该问题要求找出指定范围内所有不包含特定正整数作为因数的数的数量。通过递归地遍历可能的因数组合,并使用容斥原理来计算最终结果。
330

被折叠的 条评论
为什么被折叠?



