1 2 3 4

中北大学2020校赛 20200524

https://ac.nowcoder.com/acm/contest/5188/L

这也是一个容斥定理的题,可以互相除的因子要消去他们各自的影响

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#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;
}

  

posted @   Lesning  阅读(146)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示