题目链接:E、Modular Stability

题意:

给你一个n数,一个k,在1,2,3...n里挑选k个数,使得对于任意非负整数x,对于这k个数的任何排列顺序,然后用x对这个排列一次取模,如果最后取模结果不变,那么称它为稳定的,求稳定数组的个数。

题解:

我们知道y%x%y!=y%y%x,那么如果要想满足题意那么这个最后的结果应该是0,也就是说这n个数里面那一个最小的x,这个x可以把剩下k-1个数整除,这样的话结果就肯定是0

比如如果k=3,n=10,那么(2,4,6,8,10),我们只需要从中拿出来3个就可以,也就是排列组合C35 ,这里我们只举例x==2

因为要用到排列组合,所以这里用到了逆元的费马小定理推导,具体见:https://www.cnblogs.com/kongbursi-2292702937/p/10582258.html

代码:

#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<string>
#include<queue>
#include<deque>
#include<string.h>
#include<map>
#include <iostream>
#include <math.h>
#define Mem(a,b) memset(a,b,sizeof(a))
const double II = acos(-1);
const double PP = (II*1.0)/(180.00);
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;
const int maxn=5e5+10;
const double eps=1e-6;
const double PI=acos(-1);
const int mod=998244353;
ll v[maxn],n,k;
void find_divide()
{
for(ll i=1;i*k<=n;++i)
{
v[i]=n/i-1;
}
}
ll ppow(ll a,ll b)
{
ll ans=1;
while(b)
{
if(b&1) ans=(ans*a)%mod;
a=(a*a)%mod;
b>>=1;
}
return ans;
}
ll solve(ll now,int num)
{
ll ans=1;
for(ll i=v[now];i>v[now]-num;--i)
ans=(ans*i)%mod;
for(ll i=1;i<=num;++i)
{
ans=(ans*ppow(i,mod-2))%mod;
}
return ans;
}
int main()
{
ll sum=0;
scanf("%I64d%I64d",&n,&k);
find_divide();
for(ll i=1;i*k<=n;++i)
{ sum=(sum+solve(i,k-1))%mod;
//printf("%d**\n",sum);
}
printf("%I64d\n",sum);
return 0;
}

Educational Codeforces Round 88 (Rated for Div. 2) E、Modular Stability 逆元+思维的更多相关文章

  1. Educational Codeforces Round 88 (Rated for Div. 2) E. Modular Stability(数论)

    题目链接:https://codeforces.com/contest/1359/problem/E 题意 有一大小为 $k$ 的数组,每个元素的值在 $[1,n]$ 间,若元素间两两不等,问有多少数 ...

  2. 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$,每块花费为 ...

  3. Educational Codeforces Round 88 (Rated for Div. 2) D. Yet Another Yet Another Task(枚举/最大连续子序列)

    题目链接:https://codeforces.com/contest/1359/problem/D 题意 有一个大小为 $n$ 的数组,可以选取一段连续区间去掉其中的最大值求和,问求和的最大值为多少 ...

  4. Educational Codeforces Round 88 (Rated for Div. 2) A. Berland Poker(数学)

    题目链接:https://codeforces.com/contest/1359/problem/A 题意 $n$ 张牌可以刚好被平分给 $k$ 个人,其中有 $m$ 张 joker,当一个人手中的 ...

  5. Educational Codeforces Round 88 (Rated for Div. 2) C. Mixing Water(数学/二分)

    题目链接:https://codeforces.com/contest/1359/problem/C 题意 热水温度为 $h$,冷水温度为 $c\ (c < h)$,依次轮流取等杯的热冷水,问二 ...

  6. 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)的值尽可能 ...

  7. Educational Codeforces Round 88 (Rated for Div. 2) B、New Theatre Square C、Mixing Water

    题目链接:B.New Theatre Square 题意: 你要把所有"." 都变成"*",你可以有两个选择,第一种就是一次铺一个方块(1*1),第二种就是同一 ...

  8. Educational Codeforces Round 65 (Rated for Div. 2) E. Range Deleting(思维+coding)

    传送门 参考资料: [1]:https://blog.csdn.net/weixin_43262291/article/details/90271693 题意: 给你一个包含 n 个数的序列 a,并且 ...

  9. Educational Codeforces Round 73 (Rated for Div. 2)D(DP,思维)

    #define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;long long a[300007],b[3 ...

随机推荐

  1. requests基础封装-get/post封装

     字符串转化成字典: convert_to_dict.py: import jsonstr1 = '{"grant_type":"client_credential&qu ...

  2. explain extended;show warnings

    mysql> explain extended select count(*) from xuehao;+----+-------------+-------+------+---------- ...

  3. yum -y install gnuplot

    [root@test~]# yum -y install gnuplotLoaded plugins: fastestmirrorLoading mirror speeds from cached h ...

  4. QLibrary 加载动态库

    阅读本文大概需要 6.6分钟 一般情况下在没有头文件支持情况下,想要引入某个动态库,最好的办法就是使用「动态加载」的方法,在Qt中一般使用QLibyary来操作 常用 api QLibrary(con ...

  5. 【Sed】使用sed删除文件指定行的内容

    sed多看帮助文档,受益良多 sed -i '$d' filename 例如删除 /etc/profile的最后一行 cat -n /etc/profile ...    101  export PA ...

  6. Linux下Too many open files问题排查与解决

    作者: Grey 原文地址: Github 语雀 博客园 Too many open files是Linux系统中常见的错误,从字面意思上看就是说程序打开的文件数过多,不过这里的files不单是文件的 ...

  7. kubernets之向外部应用暴露应用

    一  通过NodePort来暴露服务 前面已经介绍的服务的一些作用,例如将集群内部的应用暴露给集群内部的pod使用,将外部的应用通过服务暴露给内部应用使用,但是服务最大的作用不仅仅是这些 而是将集群内 ...

  8. 使用gui_upload的总结

    今天使用gui_upload函数将文本文件的内容读取到内表.出现了一个问题,总是程序宕掉,出项的提示是 Type conflict when calling a function module. 原来 ...

  9. Centos 7 网卡配置

    网卡配置位置 1 /etc/sysconfig/network-scripts/ifcfg-ethx  -----其中x为网卡名称,centos 默认网卡名称为ens33 如何配置  1 2 3 4 ...

  10. mysqldumpslow基本使用

    参数解释 -s, 是表示按照何种方式排序 c: 访问计数 l: 锁定时间 r: 返回记录 t: 查询时间 al:平均锁定时间 ar:平均返回记录数 at:平均查询时间 -t, 是top n的意思,即为 ...