首页 > 其他 > 详细

牛客练习赛43F Tachibana Kanade Loves Game

时间:2019-04-06 13:17:39      阅读:135      评论:0      收藏:0      [点我收藏+]

题目地址

Link

题解

这题其实就是求1~n中有多少与2~20互质的数,然后其实只跟1~20里面的质数有关。
那么考虑容斥一下求出来一共有多少个不互质的,用n减一下就是互质的数的个数了。然后判一下ans+k是否大于q即可。题解莫反反而麻烦了。本质思路是一样的。
复杂度是\(O(T*8*2^8)\)

#include <bits/stdc++.h>
using namespace std;

#define ll long long
int p[] = {2, 3, 5, 7, 11, 13, 17, 19};
int cnt, T, m;
ll k, q, n;

int main() {
    cin >> T;
    while(T--) {
        cnt = 0; 
        cin >> k >> q >> n >> m;
        if(n < q || !k) {puts("QAQ"); continue;}
        for(int i = 0; i < 8; ++i) if(p[i] <= m) ++cnt;
        ll ans = n;
        for(int S = 1; S < (1 << cnt); ++S) {
            int tot = 0; ll sum = 1;
            for(int i = 0; i < cnt; ++i) if((S >> i) & 1) ++tot, sum *= p[i];
            if(tot & 1) ans -= n / sum;
            else ans += n / sum;
        }
        if(ans + k > q) puts("Yes");
        else puts("QAQ");
    }
}

牛客练习赛43F Tachibana Kanade Loves Game

原文:https://www.cnblogs.com/henry-1202/p/10661383.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!