1. 程式人生 > >牛客小白月賽5 A-無關(relationship)

牛客小白月賽5 A-無關(relationship)

文章目錄

題目:

傳送門

分析:

我們可以運用容斥原理解決,因為出題人保證了aa為素數,所以可以跑一遍遞迴求解

程式碼:

#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; }