Codeforces Round #729 (Div. 2)

A Odd Set

题目大意

给一个数n,给2*n个数,将他们分为n组,每组两个数,问能否使每组数的和为奇数

主要思路

只有奇数+偶数=奇数,那么只有当奇数个数==偶数个数时才能凑成

AC代码
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <stack>
#include <string>
#include <cmath>
#include <unordered_map>
#include <queue>
#include <map>
using namespace std;

#define int long long
#define debug(a) cout << #a << " = " << a << endl;
#define x first
#define y second
typedef pair<int, int> P;

const int N = 200010;
int n, a[N];

signed main(void)
{
    int T;
    cin >> T;
    while(T--)
    {
        int odd = 0, even = 0;
        cin >> n;
        for(int i = 0; i < 2 * n; i++)
        {
            int t;
            cin >> t;
            if(t % 2) odd++;
            else even++;
        }
        if(odd == even) puts("Yes");
        else puts("No");
    }
    return 0;
}

###B Plus and Multiply

题目大意

给定一个数a, 一个数b,同时还有一个从1开始的数列,数列无限长,数列中的数可以从数列中任选一个数乘a或者加b来添加,问给你一个数n,这个数是否在这个数列中

主要思路

假定一个数x = ((1 + b) * a + b + b)) * a + b = (1 + b) * a * a + (2a + 1)b = a * a + (a^2 + 2*a + 1) * b,也就是说任意一个在数列中的数,一定通过可以减去几个a来让这个数成为b的倍数,所以可以通过将给定的数n通过减0个a, 1个a…判断每个数是否是b的倍数即可

AC代码
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <stack>
#include <string>
#include <cmath>
#include <unordered_map>
#include <queue>
#include <map>
using namespace std;

#define int long long
#define debug(a) cout << #a << " = " << a << endl;
#define x first
#define y second
typedef pair<int, int> P;

signed main(void)
{
    int T;
    cin >> T;
    while(T--)
    {
        int n, a, b;
        cin >> n >> a >> b;
        bool flag = false;
        for(int i = 1; i <= n; i *= a)
        {
            if((n - i) % b == 0)
            {
                flag = true;
            }
            if(a == 1) break;
        }
        if(flag) puts("Yes");
        else puts("No");
    }
    return 0;
}

C Strange Function

题目大意

定义一个f(x)为x%i不等于0的最小正整数i,给定一个数n,求f(1) + f(2) + …+ f(n)的和

主要思路

首先我们考虑f(x)的取值最大为41,为42时说明x是141所有数的倍数,也就是为141的最小公倍数为219060189739591200,大于n的取值范围。

其次我们考虑2~41每个值对答案的贡献,所有奇数答案都为2,偶数答案一定大于2,每个数的贡献至少为2,所以我们先把答案初始化为n*2。

2比较特殊考虑完毕,如果f(x)想要有3~41中某个数i的贡献,那么x一定为1 ~ i - 1的最小公倍数的倍数,统计比n小的中有多少数是1 ~ i - 1的最小公倍数的倍数就相当于n / lcm(1 ~ i - 1), 这个数的含义是有多少数的f(x)至少能取到i,如果至少能取到i那么对答案贡献+1,所以3~41中某个数i的贡献为n / lcm(1 ~ i - 1)

AC代码
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <stack>
#include <string>
#include <cmath>
#include <unordered_map>
#include <queue>
#include <map>
using namespace std;

#define int long long
#define debug(a) cout << #a << " = " << a << endl;
#define x first
#define y second
typedef pair<int, int> P;

int gcd(int a, int b)
{
    return b ? gcd(b, a % b) : a;
}

const int N = 50, mod = 1000000007;
int a[N];

signed main(void)
{
    int x = 2;
    for(int i = 1; i <= 42; i++)
    {
        a[i] = x;

        x = x * i / gcd(x, i);
    }
    cout << a[42] << endl;
    int T;
    cin >> T;
    while(T--)
    {
        int n;
        cin >> n;
        int ans = n * 2;
        for(int i = 3; i <= 41; i++) ans = (ans + n / a[i]) % mod;
        cout << ans << endl;
    }
    return 0;
}

后续待补充!

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值