Educational Codeforces Round 88 (Rated for Div. 2) E. Modular Stability(数论)
题目链接:https://codeforces.com/contest/1359/problem/E
题意
有一大小为 $k$ 的数组,每个元素的值在 $[1,n]$ 间,若元素间两两不等,问有多少数组对于任意非负整数 $x$ 满足:
$x\ \%\ a_{1} \ \%\ a_{2} \ \%\ ... \ \%\ a_{k} = x \ \%\ a_{p1} \ \%\ a_{p2} \ \%\ ... \ \%\ a_{p_k}$
其中,$p$ 为 $k$ 的任一种排列,$a_1<a_2<...<a_k$ 。
题解
易得该式的结果取决于最小的 $a_i$ 。
假设数组 $a$ 中最小的数为 $a_1$,设 $x = na_1 + m\ (\ n ≥ 0,\ 0 ≤ m < a_1\ )$,该式的值即为 $m$,由此推出 $x \ \%\ a_i$ 后 $\%\ a_1$ 仍为 $m$,即 $(n_1a_1 + m) \ \%\ a_i = n_2a_1 + m$,所以 $a_i$ 为 $a_1$ 的倍数。
又因为 $k$ 个数两两不同,所以枚举 $a_1$ 的值,从余下 $\frac{n}{a_1} - 1$ 个 $a_1$ 的倍数中选取 $k - 1$ 个即可。
即 $\sum_{i = 1}^{n} C_{\frac{n}{i} - 1}^{k - 1}$ 。
代码
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
const int mod = 998244353; ll fpow(ll a, ll b) {
ll res = 1;
while (b > 0) {
if (b & 1) res = res * a % mod;
a = a * a % mod;
b >>= 1;
}
return res;
} ll inv(ll x) {
return fpow(x, mod - 2);
} ll C(ll n, ll m) {
if (n < m) return 0;
ll res = 1;
ll mi = min(m, n - m);
for (int i = 1; i <= mi; i++)
res = res * (n - i + 1) % mod * inv(i) % mod;
return res;
} int main() {
int n, k; cin >> n >> k;
ll ans = 0;
for (int i = 1; i <= n; i++)
ans += C(n / i - 1, k - 1), ans %= mod;
cout << ans << "\n";
}
Educational Codeforces Round 88 (Rated for Div. 2) E. Modular Stability(数论)的更多相关文章
- Educational Codeforces Round 88 (Rated for Div. 2) B. New Theatre Square(贪心)
题目链接:https://codeforces.com/contest/1359/problem/B 题意 有一块 $n \times m$ 的地板和两种瓷砖: $1 \times 1$,每块花费为 ...
- Educational Codeforces Round 88 (Rated for Div. 2) D. Yet Another Yet Another Task(枚举/最大连续子序列)
题目链接:https://codeforces.com/contest/1359/problem/D 题意 有一个大小为 $n$ 的数组,可以选取一段连续区间去掉其中的最大值求和,问求和的最大值为多少 ...
- Educational Codeforces Round 88 (Rated for Div. 2) A. Berland Poker(数学)
题目链接:https://codeforces.com/contest/1359/problem/A 题意 $n$ 张牌可以刚好被平分给 $k$ 个人,其中有 $m$ 张 joker,当一个人手中的 ...
- Educational Codeforces Round 88 (Rated for Div. 2) C. Mixing Water(数学/二分)
题目链接:https://codeforces.com/contest/1359/problem/C 题意 热水温度为 $h$,冷水温度为 $c\ (c < h)$,依次轮流取等杯的热冷水,问二 ...
- Educational Codeforces Round 88 (Rated for Div. 2) E、Modular Stability 逆元+思维
题目链接:E.Modular Stability 题意: 给你一个n数,一个k,在1,2,3...n里挑选k个数,使得对于任意非负整数x,对于这k个数的任何排列顺序,然后用x对这个排列一次取模,如果最 ...
- Educational Codeforces Round 88 (Rated for Div. 2) D、Yet Another Yet Another Task
题意: 给你一个含n个数a1,a2...an的数组,你要找到一个区间[l,r],使得al+a(l+1)+...+a(r-1)+ar减去max(al,a(l+1),...,a(r-1),ar)的值尽可能 ...
- Educational Codeforces Round 88 (Rated for Div. 2) B、New Theatre Square C、Mixing Water
题目链接:B.New Theatre Square 题意: 你要把所有"." 都变成"*",你可以有两个选择,第一种就是一次铺一个方块(1*1),第二种就是同一 ...
- Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship
Problem Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...
- Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)
Problem Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...
随机推荐
- 【Java基础】Java11 新特性
Java11 新特性 新增字符串处理方法 新增方法: 判断字符串是否为空白 " ".isBlank(); // true 去除首尾空白 " Javastack " ...
- Spring Boot超详细用户管理项目(零)——开发前准备
开始前的软件准备:(编写中:未完成) 使用软件介绍: Java版本:Java SE 11(LTS) 开发工具:IDEA(2020.3版本) Linux系统: 数据库: Java 版本:Java SE ...
- 【Spring】Spring中的Bean - 3、Bean的作用域
Bean的作用域 简单记录-Java EE企业级应用开发教程(Spring+Spring MVC+MyBatis)-Spring中的Bean 通过Spring容器创建一个Bean的实例时,不仅可以完成 ...
- BAPI_SALESORDER_CREATEFROMDAT2 条件 定价元素
用函数 BAPI_SALESORDER_CREATEFROMDAT2创建SO的时候,遇见个问题,就是如图: 会多出来一个类型,搞了半天,发现是一个函数里的一个参数,我没有设置: LOGIC_SWITC ...
- Nginx(七):location的使用以及nginx关闭原理
上一篇中,我们了解了如何nginx的配置原则及解析框架,以及解析location配置的具体实现,相信大家对该部分已经有了比较深刻的认识. 本篇,我们进一步来了解下,解析之后的配置,如何应用到实际中的吧 ...
- 前端面试之CSS权重问题!
前端面试之CSS权重问题! 下面的权重按照从小到大来排列! 1.通用选择器(*) 2.元素(类型)选择器 权重1 3.类选择器 权重10 4.属性选择器 5.伪类 6.ID 选择器 权重100 7.内 ...
- logging philosophy 日志哲学
Go kit - Frequently asked questions https://gokit.io/faq/ Logging - Why is package log so different? ...
- (ETL)ETL架构师面试题(转载)
1. What is a logical data mapping and what does it mean to the ETL team?什么是逻辑数据映射?它对ETL项目组的作用是什么? 答: ...
- libevent之基于socket的bufferevent
基于socket的bufferevent由一个socket的传输层和read/write buffer组成.区别于常规的event,当socket可读或者可写时会回调用户的callback,buffe ...
- 列表,元祖,range
列表是python中的基础数据类型之一,其他语言中也有类似于列表的数据类型,比如js中叫数组,他是以[]括起来,每个元素以逗号隔开,而且他里面可以存放各种数据类型比如: li = ['alex',12 ...