Codeforces Round #722 (Div. 2) D. Kavi on Pairing Duty(思维)

传送门

题意:将1~2n个点两两相连,使得任意两条线段要么相互包含,要么长度相同,问方案数

思路:考虑最长线段的长度len

(1)len > n 时,外层包含内层,方案数为n = 1,n = 2……,n = n - 1 的方案数总和

(2)len <= n 时,所有线段长度相同,长度为len 的线段相互交叉需要2 * len个点,所以方案数为 n 的因子数

综上,n 的方案数为前缀和 + n的因子数

参考思路:https://blog.csdn.net/quinn18/article/details/117236978

#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
const int inf = 0x3f3f3f3f;
const ll mod = 998244353;
const int N = 1e6 + 10;

int fac[N], n;

void init() {
    for(int i = 1; i <= n; ++i)
        for(int j = i; j <= n; j += i) fac[j]++;
}

int main() {
    scanf("%d", &n);
    if(n == 1) {
        printf("1\n");
        return 0;
    }
    init();
    ll sum = 1;
    for(int i = 2; i < n; ++i)
        sum = (2 * sum % mod + fac[i]) % mod;
    printf("%lld\n", (sum + fac[n]) % mod);
    return 0;
}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值