题目大意:求$G^{\sum_{m|n} C_{n}^{m}}\;mod\;999911659\;$的值$(n,g<=10^{9})$

并没有想到欧拉定理..

999911659是一个质数,所以$\varphi(p)=p-1$

利用欧拉定理,降幂化简式子$G^{\sum_{m|n} C_{n}^{m}\;mod\;\varphi(p)}$

这样,指数部分可以用$Lucas$+中国剩余定理求解

然而..$G>10^9$很大,可能和模数$999911659$不互质!所以质数要额外加上$\varphi(p)$

  1. #include <map>
  2. #include <queue>
  3. #include <cmath>
  4. #include <cstdio>
  5. #include <cstring>
  6. #include <algorithm>
  7. #define N 10100
  8. #define ull unsigned long long
  9. #define ll long long
  10. #define maxn 36000
  11. using namespace std;
  12.  
  13. ll n,g;
  14. const ll m[]={,,,};
  15.  
  16. ll qpow(ll x,ll y,const ll &mod){
  17. ll ans=;
  18. while(y){
  19. if(y&) ans=(ans*x)%mod;
  20. x=(x*x)%mod,y>>=;
  21. }return ans;
  22. }
  23. namespace excrt{
  24. ll exgcd(ll a,ll b,ll &x,ll &y){
  25. if(!b) {x=,y=;return a;}
  26. ll ans=exgcd(b,a%b,x,y);
  27. ll t=x;x=y,y=t-a/b*y;
  28. return ans;
  29. }
  30. ll qadd(ll x,ll y,const ll &mod){
  31. ll ans=;
  32. while(y){
  33. if(y&) ans=(ans+x)%mod;
  34. x=(x+x)%mod,y>>=;
  35. }return ans;
  36. }
  37. ll ans=,M=;
  38. void insert(ll A,ll B)
  39. {
  40. ll a=A,b=B,c=(a-ans%b+b)%b,x,y,g;
  41. g=exgcd(M,b,x,y);b/=g;
  42. //if(c/g!=0) return;
  43. //x=qadd(x,c/g,b);
  44. x=x*(c/g)%b;
  45. ans+=x*M,M*=b,ans=(ans%M+M)%M;
  46. }
  47. };
  48. int son[N],d[N],ps[N],num,cnt;
  49. namespace calc{
  50. ll mul[maxn+],inv[maxn+],minv[maxn+];
  51. void Pre(const ll &mo)
  52. {
  53. mul[]=mul[]=inv[]=inv[]=minv[]=minv[]=;
  54. for(int i=;i<mo;i++){
  55. mul[i]=mul[i-]*i%mo;
  56. inv[i]=1ll*(mo-mo/i)*inv[mo%i]%mo;
  57. minv[i]=minv[i-]*inv[i]%mo;
  58. }
  59. }
  60. ll C(ll a,ll b,const ll &mo)
  61. {return mul[a]*minv[b]%mo*minv[a-b]%mo;}
  62. ll Lucas(ll a,ll b,const ll &mo)
  63. {
  64. if(b>a) return ;
  65. if(a<mo&&b<mo) return C(a,b,mo);
  66. return Lucas(a/mo,b/mo,mo)*Lucas(a%mo,b%mo,mo)%mo;
  67. }
  68. ll solve(const ll &mo)
  69. {
  70. for(int i=;i<mo;i++)
  71. mul[i]=inv[i]=minv[i]=;
  72. Pre(mo);ll ans=;
  73. for(int i=;i<=cnt;i++)
  74. (ans+=Lucas(n,son[i],mo))%=mo;
  75. return ans;
  76. }
  77. };
  78. void dfs_son(int i,ll s)
  79. {
  80. if(i>num) {son[++cnt]=s;return;}
  81. for(int j=;j<=d[i];j++)
  82. dfs_son(i+,s),s*=ps[i];
  83. }
  84. void get_son(ll a)
  85. {
  86. int sq=sqrt(a);
  87. for(int i=;i<=sq;i++)
  88. if(a%i==){
  89. ps[++num]=i;
  90. while(a%i==)
  91. d[num]++,a/=i;
  92. }
  93. if(a!=)
  94. ps[++num]=a,d[num]++;
  95. dfs_son(,);
  96. }
  97. const ll smod=;
  98.  
  99. int main()
  100. {
  101. scanf("%lld%lld",&n,&g);
  102. get_son(n);
  103. for(int i=;i<;i++)
  104. {
  105. ll ans=calc::solve(m[i]);
  106. excrt::insert(ans,m[i]);
  107. }
  108. ll pw=excrt::ans;
  109. ll ans=qpow(g,pw+smod-,smod);
  110. printf("%lld\n",ans);
  111. return ;
  112. }

BZOJ 1951 [SDOI2010]古代猪文 (组合数学+欧拉降幂+中国剩余定理)的更多相关文章

  1. BZOJ 1951: [Sdoi2010]古代猪文( 数论 )

    显然答案是G^∑C(d,N)(d|N).O(N^0.5)枚举N的约数.取模的数999911659是质数, 考虑欧拉定理a^phi(p)=1(mod p)(a与p互质), 那么a^t mod p = a ...

  2. BZOJ 1951: [Sdoi2010]古代猪文 [Lucas定理 中国剩余定理]

    1951: [Sdoi2010]古代猪文 Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 2194  Solved: 919[Submit][Status] ...

  3. [SDOI2010]古代猪文 (欧拉,卢卡斯,中国剩余)

    [SDOI2010]古代猪文 \(solution:\) 这道题感觉综合性极强,用到了许多数论中的知识: 质因子,约数,组合数 欧拉定理 卢卡斯定理 中国剩余定理 首先我们读题,发现题目需要我们枚举k ...

  4. 【刷题】BZOJ 1951 [Sdoi2010]古代猪文

    Description "在那山的那边海的那边有一群小肥猪.他们活泼又聪明,他们调皮又灵敏.他们自由自在生活在那绿色的大草坪,他们善良勇敢相互都关心--" --选自猪王国民歌 很久 ...

  5. bzoj 1951 [Sdoi2010]古代猪文(数论知识)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1951 [思路] 一道优(e)秀(xin)的数论题. 首先我们要求的是(G^sigma{ ...

  6. bzoj 1951 [Sdoi2010]古代猪文 ——数学综合

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1951 数学综合题. 费马小定理得指数可以%999911658,又发现这个数可以质因数分解.所 ...

  7. bzoj 1951: [Sdoi2010]古代猪文 【中国剩余定理+欧拉定理+组合数学+卢卡斯定理】

    首先化简,题目要求的是 \[ G^{\sum_{i|n}C_{n}^{i}}\%p \] 对于乘方形式快速幂就行了,因为p是质数,所以可以用欧拉定理 \[ G^{\sum_{i|n}C_{n}^{i} ...

  8. bzoj 1951: [Sdoi2010]古代猪文

    #include<cstdio> #include<iostream> #include<cstring> #include<cmath> #defin ...

  9. BZOJ.1951.[SDOI2010]古代猪文(费马小定理 Lucas CRT)

    题目链接 \(Description\) 给定N,G,求\[G^{\sum_{k|N}C_n^k}\mod\ 999911659\] \(Solution\) 由费马小定理,可以先对次数化简,即求\( ...

随机推荐

  1. MySQL查询结果保存到本地

    #!/bin/bash mysql -h<公网IP> -P<端口号> -u<用户名> -p<密码> -D<指定数据库> >/Users ...

  2. ZBrush中的布料技巧分享

    今天主要给大家介绍一种在ZBrush®3D图形绘制软件中创建特定类型的布料的技巧,这种方法简单却非常强大. 这个想法源自下面这张图: 我们今天所要讲的技巧可能不是实现复杂的服装设计最有效的方法,但确实 ...

  3. JS 数值转换、加减乘除

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  4. Hibernate---criteria的具体使用列子

    方法 说明 Restrictions.eq = Restrictions.allEq 利用Map来进行多个等于的限制 Restrictions.gt > Restrictions.ge > ...

  5. Pyhton学习——Day25

    #面向对象的几个方法#1.静态方法@staticmethod,不能访问类属性,也不能访问实例属性,只是类的工具包#2.类方法:@classmethod,在函数属性前加上类方法,显示为(cls)代表类, ...

  6. 六、利用frp穿透连接内网的linx系统和windows系统

    服务端的配置 # frps.ini [common] bind_port = 7000 说明:防火墙放行该端口 启动:./frps -c ./frps.ini 后台启动:nohup ./frps -c ...

  7. Vue系列(三):组件及数据传递、路由、单文件组件、vue-cli脚手架

    上一篇:Vue系列(二):发送Ajax.JSONP请求.Vue生命周期及实例属性和方法.自定义指令与过渡 一. 组件component 1. 什么是组件? 组件(Component)是 Vue.js ...

  8. python_传递任意数量的实参

    '''def name(*args): #python创建一个空元组,将收到的所有值都封装在这个元组中 """打印所有姓名""" for i ...

  9. [luogu] P4551 最长异或路径(贪心)

    P4551 最长异或路径 题目描述 给定一棵\(n\)个点的带权树,结点下标从\(1\)开始到\(N\).寻找树中找两个结点,求最长的异或路径. 异或路径指的是指两个结点之间唯一路径上的所有边权的异或 ...

  10. Vue常用的GitHub项目

    Vue常用的GitHub项目(Demo案例) 应用实例 https://github.com/pagekit/pa... pagekit-轻量级的CMS建站系统 https://github.com/ ...