https://ac.nowcoder.com/acm/contest/5188/L
这也是一个容斥定理的题,可以互相除的因子要消去他们各自的影响
#include<iostream> #include<vector> #include<algorithm> using namespace std; typedef long long ll; vector<ll>ins; ll f[400]; int main(){ ll x = 20200524; for(ll i=1;i*i<=x;i++){ if(x % i == 0){ ins.push_back(i); if(i * i != x) ins.push_back(x/i); } } sort(ins.begin(),ins.end()); int n,m; int t; cin>>t; while(t--){ cin>>n>>m; int len = ins.size(); for(int i=0;i<ins.size();i++){ f[i] = n/ins[i]; } for(int i=len-1;i>=0;i--){ for(int j=len-1;j>i;j--){ if(ins[j] % ins[i] == 0){ f[i] -= f[j]; } } } ll ans = 0; for(int i=0;i<len;i++){ ll c = x/ins[i]; if(c){ c = m/c; ans += (f[i]*(c)); } } cout<<ans<<endl; } return 0; }