牛客小白月赛5 A-无关(relationship)

版权声明:喜欢请点个大拇指,感谢各位dalao。弱弱说下,转载要出处呦 https://blog.csdn.net/qq_35786326/article/details/82927771


题目:

传送门


分析:

我们可以运用容斥原理解决,因为出题人保证了 a a 为素数,所以可以跑一遍递归求解


代码:

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>  
#include<cstdlib>
#include<algorithm>
#include<set>
#include<queue>
#include<vector>
#include<map>
#include<list>
#include<ctime>
#include<iomanip>
#include<string>
#include<bitset>
#include<deque>
#include<set>
#define LL long long
#define h happy
#define ch cheap
using namespace std;
inline LL read() {
    LL d=0,f=1;char s=getchar();
    while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}
    while(s>='0'&&s<='9'){d=d*10+s-'0';s=getchar();}
    return d*f;
}
LL l=read(),r=read(),k=read();
int a[25];
LL _233(LL i,LL n)
{
    if(i>k) return n;
    else return _233(i+1,n)-_233(i+1,n/a[i]);
}
int main()
{
   for(int i=1;i<=k;i++) a[i]=read();
   cout<<_233(1,r)-_233(1,l-1);
   return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_35786326/article/details/82927771