BZOJ 1951 [SDOI2010]古代猪文 (组合数学+欧拉降幂+中国剩余定理)
题目大意:求$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)$
- #include <map>
- #include <queue>
- #include <cmath>
- #include <cstdio>
- #include <cstring>
- #include <algorithm>
- #define N 10100
- #define ull unsigned long long
- #define ll long long
- #define maxn 36000
- using namespace std;
- ll n,g;
- const ll m[]={,,,};
- ll qpow(ll x,ll y,const ll &mod){
- ll ans=;
- while(y){
- if(y&) ans=(ans*x)%mod;
- x=(x*x)%mod,y>>=;
- }return ans;
- }
- namespace excrt{
- ll exgcd(ll a,ll b,ll &x,ll &y){
- if(!b) {x=,y=;return a;}
- ll ans=exgcd(b,a%b,x,y);
- ll t=x;x=y,y=t-a/b*y;
- return ans;
- }
- ll qadd(ll x,ll y,const ll &mod){
- ll ans=;
- while(y){
- if(y&) ans=(ans+x)%mod;
- x=(x+x)%mod,y>>=;
- }return ans;
- }
- ll ans=,M=;
- void insert(ll A,ll B)
- {
- ll a=A,b=B,c=(a-ans%b+b)%b,x,y,g;
- g=exgcd(M,b,x,y);b/=g;
- //if(c/g!=0) return;
- //x=qadd(x,c/g,b);
- x=x*(c/g)%b;
- ans+=x*M,M*=b,ans=(ans%M+M)%M;
- }
- };
- int son[N],d[N],ps[N],num,cnt;
- namespace calc{
- ll mul[maxn+],inv[maxn+],minv[maxn+];
- void Pre(const ll &mo)
- {
- mul[]=mul[]=inv[]=inv[]=minv[]=minv[]=;
- for(int i=;i<mo;i++){
- mul[i]=mul[i-]*i%mo;
- inv[i]=1ll*(mo-mo/i)*inv[mo%i]%mo;
- minv[i]=minv[i-]*inv[i]%mo;
- }
- }
- ll C(ll a,ll b,const ll &mo)
- {return mul[a]*minv[b]%mo*minv[a-b]%mo;}
- ll Lucas(ll a,ll b,const ll &mo)
- {
- if(b>a) return ;
- if(a<mo&&b<mo) return C(a,b,mo);
- return Lucas(a/mo,b/mo,mo)*Lucas(a%mo,b%mo,mo)%mo;
- }
- ll solve(const ll &mo)
- {
- for(int i=;i<mo;i++)
- mul[i]=inv[i]=minv[i]=;
- Pre(mo);ll ans=;
- for(int i=;i<=cnt;i++)
- (ans+=Lucas(n,son[i],mo))%=mo;
- return ans;
- }
- };
- void dfs_son(int i,ll s)
- {
- if(i>num) {son[++cnt]=s;return;}
- for(int j=;j<=d[i];j++)
- dfs_son(i+,s),s*=ps[i];
- }
- void get_son(ll a)
- {
- int sq=sqrt(a);
- for(int i=;i<=sq;i++)
- if(a%i==){
- ps[++num]=i;
- while(a%i==)
- d[num]++,a/=i;
- }
- if(a!=)
- ps[++num]=a,d[num]++;
- dfs_son(,);
- }
- const ll smod=;
- int main()
- {
- scanf("%lld%lld",&n,&g);
- get_son(n);
- for(int i=;i<;i++)
- {
- ll ans=calc::solve(m[i]);
- excrt::insert(ans,m[i]);
- }
- ll pw=excrt::ans;
- ll ans=qpow(g,pw+smod-,smod);
- printf("%lld\n",ans);
- return ;
- }
BZOJ 1951 [SDOI2010]古代猪文 (组合数学+欧拉降幂+中国剩余定理)的更多相关文章
- 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 ...
- BZOJ 1951: [Sdoi2010]古代猪文 [Lucas定理 中国剩余定理]
1951: [Sdoi2010]古代猪文 Time Limit: 1 Sec Memory Limit: 64 MBSubmit: 2194 Solved: 919[Submit][Status] ...
- [SDOI2010]古代猪文 (欧拉,卢卡斯,中国剩余)
[SDOI2010]古代猪文 \(solution:\) 这道题感觉综合性极强,用到了许多数论中的知识: 质因子,约数,组合数 欧拉定理 卢卡斯定理 中国剩余定理 首先我们读题,发现题目需要我们枚举k ...
- 【刷题】BZOJ 1951 [Sdoi2010]古代猪文
Description "在那山的那边海的那边有一群小肥猪.他们活泼又聪明,他们调皮又灵敏.他们自由自在生活在那绿色的大草坪,他们善良勇敢相互都关心--" --选自猪王国民歌 很久 ...
- bzoj 1951 [Sdoi2010]古代猪文(数论知识)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1951 [思路] 一道优(e)秀(xin)的数论题. 首先我们要求的是(G^sigma{ ...
- bzoj 1951 [Sdoi2010]古代猪文 ——数学综合
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1951 数学综合题. 费马小定理得指数可以%999911658,又发现这个数可以质因数分解.所 ...
- bzoj 1951: [Sdoi2010]古代猪文 【中国剩余定理+欧拉定理+组合数学+卢卡斯定理】
首先化简,题目要求的是 \[ G^{\sum_{i|n}C_{n}^{i}}\%p \] 对于乘方形式快速幂就行了,因为p是质数,所以可以用欧拉定理 \[ G^{\sum_{i|n}C_{n}^{i} ...
- bzoj 1951: [Sdoi2010]古代猪文
#include<cstdio> #include<iostream> #include<cstring> #include<cmath> #defin ...
- BZOJ.1951.[SDOI2010]古代猪文(费马小定理 Lucas CRT)
题目链接 \(Description\) 给定N,G,求\[G^{\sum_{k|N}C_n^k}\mod\ 999911659\] \(Solution\) 由费马小定理,可以先对次数化简,即求\( ...
随机推荐
- MySQL查询结果保存到本地
#!/bin/bash mysql -h<公网IP> -P<端口号> -u<用户名> -p<密码> -D<指定数据库> >/Users ...
- ZBrush中的布料技巧分享
今天主要给大家介绍一种在ZBrush®3D图形绘制软件中创建特定类型的布料的技巧,这种方法简单却非常强大. 这个想法源自下面这张图: 我们今天所要讲的技巧可能不是实现复杂的服装设计最有效的方法,但确实 ...
- JS 数值转换、加减乘除
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- Hibernate---criteria的具体使用列子
方法 说明 Restrictions.eq = Restrictions.allEq 利用Map来进行多个等于的限制 Restrictions.gt > Restrictions.ge > ...
- Pyhton学习——Day25
#面向对象的几个方法#1.静态方法@staticmethod,不能访问类属性,也不能访问实例属性,只是类的工具包#2.类方法:@classmethod,在函数属性前加上类方法,显示为(cls)代表类, ...
- 六、利用frp穿透连接内网的linx系统和windows系统
服务端的配置 # frps.ini [common] bind_port = 7000 说明:防火墙放行该端口 启动:./frps -c ./frps.ini 后台启动:nohup ./frps -c ...
- Vue系列(三):组件及数据传递、路由、单文件组件、vue-cli脚手架
上一篇:Vue系列(二):发送Ajax.JSONP请求.Vue生命周期及实例属性和方法.自定义指令与过渡 一. 组件component 1. 什么是组件? 组件(Component)是 Vue.js ...
- python_传递任意数量的实参
'''def name(*args): #python创建一个空元组,将收到的所有值都封装在这个元组中 """打印所有姓名""" for i ...
- [luogu] P4551 最长异或路径(贪心)
P4551 最长异或路径 题目描述 给定一棵\(n\)个点的带权树,结点下标从\(1\)开始到\(N\).寻找树中找两个结点,求最长的异或路径. 异或路径指的是指两个结点之间唯一路径上的所有边权的异或 ...
- Vue常用的GitHub项目
Vue常用的GitHub项目(Demo案例) 应用实例 https://github.com/pagekit/pa... pagekit-轻量级的CMS建站系统 https://github.com/ ...