数论题 gcd 约数 dfs 容斥
n<=15 a,b<=10^9 N<=10^4
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<cstdio> #define LL long long int n, a, b, ans, t[20]; LL gcd(LL x, LL y) { if (!y) return x; return gcd(y, x%y); } void dfs(int cnt, int step, LL d) { if (d > b) return; if (step == n+1) { if (cnt&1) { ans -= b/d-(a-1)/d; } else { ans += b/d-(a-1)/d; } return; } dfs(cnt, step+1, d); dfs(cnt+1, step+1, d*t[step]/gcd(d, t[step])); } int main() { scanf("%d",&n); for (int i=1; i<=n;++i) { scanf("%d", &t[i]); } scanf("%d%d",&a,&b); dfs(0,1,6); printf("%d\n",ans); return 0; }