题解:

当奇数

发现答案就是C(n,1)^2+C(n,3)^2+。。。C(n,n)^2

倒序相加,发现就是C(2n,n) 所以答案就是C(2n,n)/2

当偶数

好像并不会证

打表出来可以得到

2.当n为偶数且为4的倍数时,答案为C(2n,n)+C(n,n/2)/2

3.当n为偶数且不为4的倍数时,答案为C(2n,n)-C(n,n/2)/2

另外Claris告诉我在p较小时可以数位dp来求

先用lucas定理 C(n,m)=C(n%p,m%p)*C(n/p,m/p)

然后我们就可以把n表示成p进制

答案就是m在p进制下和对应n求C的乘积

然后我们可以数位dp这个东西

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define rint register ll
  5. #define IL inline
  6. #define rep(i,h,t) for (rint i=h;i<=t;i++)
  7. #define dep(i,t,h) for (rint i=t;i>=h;i--)
  8. const ll p=
  9. ;
  10. const ll mo=
  11. ;
  12. const ll INF=1e18;
  13. const ll N=2e6;
  14. ll n,cnt=,a[],jc1[N],jc2[N],f[N][][];
  15. void gcd(ll x,ll y,ll &a,ll &b)
  16. {
  17. if (y==)
  18. {
  19. a=; b=; return;
  20. }
  21. gcd(y,x%y,b,a);
  22. b-=a*(x/y);
  23. }
  24. ll C(ll x,ll y)
  25. {
  26. if (x<y) return();
  27. return jc1[x]*jc2[y]%p*jc2[x-y]%p;
  28. }
  29. void jf(ll &x,ll y)
  30. {
  31. x+=y;
  32. if (x>p) x-=p;
  33. }
  34. int main()
  35. {
  36. cin>>n;
  37. while (n) a[++cnt]=n%p,n/=p;
  38. jc1[]=jc2[]=;
  39. rep(i,,p)
  40. {
  41. jc1[i]=(jc1[i-]*i)%p;
  42. jc1[i]=(jc1[i]+p)%p;
  43. ll x,y;
  44. gcd(i,p,x,y);
  45. jc2[i]=(jc2[i-]*x)%p;
  46. jc2[i]=(jc2[i]+p)%p;
  47. }
  48. f[cnt+][][]=;
  49. dep(j,cnt,)
  50. {
  51. ll tmp1j=,tmp1o=;
  52. rep(i,,a[j]-)
  53. {
  54. ll kk=C(a[j],i);
  55. kk=(kk*kk)%mo;
  56. if (i%)
  57. jf(tmp1j,kk);
  58. else jf(tmp1o,kk);
  59. }
  60. f[j][][]=(f[j+][][]*tmp1o%mo+f[j+][][]*tmp1j%mo)%mo;
  61. f[j][][]=(f[j+][][]*tmp1j%mo+f[j+][][]*tmp1o%mo)%mo;
  62. if (a[j]%) jf(tmp1j,); else jf(tmp1o,);
  63. f[j][][]+=(f[j+][][]*tmp1o%mo+f[j+][][]*tmp1j%mo)%mo;
  64. f[j][][]+=(f[j+][][]*tmp1j%mo+f[j+][][]*tmp1o%mo)%mo;
  65. if (f[j+][][]) f[j][(+a[j])%][]=;
  66. else f[j][a[j]%][]=;
  67. }
  68. ll ans=(f[][][]+f[][][])%mo;
  69. cout<<ans<<endl;
  70. }

【loj6142】「2017 山东三轮集训 Day6」A 结论题+Lucas定理的更多相关文章

  1. Loj #6142. 「2017 山东三轮集训 Day6」A

    link: https://loj.ac/problem/6142 推完一波式子之后发现求的是:ΣC(N,i)^2, 其中i是偶数. 然后就可以卢卡斯乱搞了,分奇偶和之前的答案合并就好了233. #i ...

  2. 「2017 山东三轮集训 Day1」Flair

    模拟赛的题 好神仙啊 题面在这里 之前的Solution很蠢 现在已经update.... 题意 有$ n$个商品价格均为$ 1$,您有$ m$种面值的货币,面值为$ C_1..C_m$ 每种物品你有 ...

  3. 【loj6145】「2017 山东三轮集训 Day7」Easy 动态点分治+线段树

    题目描述 给你一棵 $n$ 个点的树,边有边权.$m$ 次询问,每次给出 $l$ .$r$ .$x$ ,求 $\text{Min}_{i=l}^r\text{dis}(i,x)$ . $n,m\le ...

  4. loj #6138. 「2017 山东三轮集训 Day4」Right

    题目: 题解: 暴力一波 \(SG\) 函数可以发现这么一个规律: \(p\) 为奇数的时候 : \(SG(n) = n \% 2\) \(p\) 为偶数的时候 : \(SG(n) = n \% (p ...

  5. loj #6136. 「2017 山东三轮集训 Day4」Left

    题目: 题解: 我们可以发现所有的交换器都是一个位置连接着下一层左侧的排序网络,另一个位置连着另一侧的排序网络. 而下一层是由两个更低阶的排序网络构成的. 两个网络互不干扰.所以我们可以通过第一行和最 ...

  6. 「2017 山东三轮集训 Day7」Easy

    一棵带边权的树,多次询问 $x$ 到编号为 $[l,r]$ 的点最短距离是多少 $n \leq 100000$ sol: 动态点分治,每层重心维护到所有点的距离 查询的时候在管辖这个点的 log 层线 ...

  7. #6145. 「2017 山东三轮集训 Day7」Easy 动态点分治

    \(\color{#0066ff}{题目描述}\) JOHNKRAM 最近在参加 C_SUNSHINE 举办的聚会. C 国一共有 n 座城市,这些城市由 n−1 条无向道路连接.任意两座城市之间有且 ...

  8. LOJ #6145. 「2017 山东三轮集训 Day7」Easy 点分树+线段树

    这个就比较简单了~ Code: #include <cstdio> #include <algorithm> #define N 100004 #define inf 1000 ...

  9. 「2017 山东三轮集训 Day7 解题报告

    「2017 山东三轮集训 Day7」Easy 练习一下动态点分 每个点开一个线段树维护子树到它的距离 然后随便查询一下就可以了 注意线段树开大点... Code: #include <cstdi ...

随机推荐

  1. QT 开发小记

    1.开发socket网络通信时,需要在.pro 文件中添加 network项 QT       +=  network 2. 报错: mutilple definition of  时,查看 .pro ...

  2. Qt5全局热键第三方库qxtglobalshortcut5使用

    1.下载第三方库https://github.com/ddqd/qxtglobalshortcut5. 2.把qxtglobalshortcut5文件放在项目目录下,在项目.pro加入一句,inclu ...

  3. python操作三大主流数据库(10)python操作mongodb数据库④mongodb新闻项目实战

    python操作mongodb数据库④mongodb新闻项目实战 参考文档:http://flask-mongoengine.readthedocs.io/en/latest/ 目录: [root@n ...

  4. 缓存系列之五:通过codis3.2实现redis3.2.8集群的管理

    通过codis3.2实现redis3.2.8集群 一:Codis 是一个分布式 Redis 解决方案, 对于上层的应用来说, 连接到 Codis Proxy 和连接原生的 Redis Server 没 ...

  5. 配置国内 Docker Registry Mirror

    由于国内特殊的网络环境,往往我们从Docker Hub中拉取镜像并不能成功,而且速度特别慢. 那么我们可以给Docker配置一个国内的registry mirror,当我们需要的镜像在mirror中则 ...

  6. 7-Links

    Use the <a> element to define a link Use the href attribute to define the link address Use the ...

  7. mysql:赋予用户权限、查看及修改端口号

    一.mysql 赋给用户权限 grant all privileges on *.* to joe@localhost identified by '1'; flush privileges; 即用u ...

  8. 【原创】运维基础之Docker(5)docker部署airflow

    部署方式:docker+airflow+mysql+LocalExecutor 使用airflow的docker镜像 https://hub.docker.com/r/puckel/docker-ai ...

  9. mysql修改字段长度及pymysql.err.DataError: (1406, "Data too long for column 'name' at row 1")错误

    文章链接:修改字段:https://blog.csdn.net/xiejunna/article/details/78580682 错误分析:https://blog.csdn.net/qq_4214 ...

  10. python-进程池与线程池,协程

    一.进程池与线程池 实现并发的手段有两种,多线程和多进程.注:并发是指多个任务看起来是同时运行的.主要是切换+保存状态. 当我们需要执行的并发任务大于cpu的核数时,我们需要知道一个操作系统不能无限的 ...