题目大意:求$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]古代猪文 (组合数学+欧拉降幂+中国剩余定理)的更多相关文章

  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. IPv6特性,以及SLAAC过程

    1. IPv6特性 支持即插即用: 路由器发现(Router Discovery):当一个节点连接到一个IPv6的链路上时,它能够发现本地的路由器,而不必借助动态主机配置协议(DHCP). 前缀发现( ...

  2. stylus 移动端边框1像素问题解决方案

    border($border-width = 1px, $border-color = #ccc, $border-style = solid, $radius = 0) // 为边框位置提供定位参考 ...

  3. BZOJ 3676 [Apio2014]回文串 (后缀自动机+manacher/回文自动机)

    题目大意: 给你一个字符串,求其中回文子串的长度*出现次数的最大值 明明是PAM裸题我干嘛要用SAM做 回文子串有一个神奇的性质,一个字符串本质不同的回文子串个数是$O(n)$级别的 用$manach ...

  4. [转]Python常用字符串

    转自:http://blog.csdn.net/daemonpei/article/details/6325762 字符串相关操作: + :string1+string2 #联接字符串,将后一个串链接 ...

  5. Java并发和多线程4:使用通用同步工具CountDownLatch实现线程等待

    CountDownLatch,一个同步辅助类,在完成一组正在其他线程中执行的操作之前,它允许一个或多个线程一直等待. 用给定的计数 初始化 CountDownLatch.由于调用了 countDown ...

  6. vue实现双向绑定原理

  7. MyBatis学习总结(8)——Mybatis3.x与Spring4.x整合

    一.搭建开发环境 1.1.使用Maven创建Web项目 执行如下命令: mvn archetype:create -DgroupId=me.gacl -DartifactId=spring4-myba ...

  8. 数据结构实现(四)二叉查找树java实现

    转载 http://www.cnblogs.com/CherishFX/p/4625382.html 二叉查找树的定义: 二叉查找树或者是一颗空树,或者是一颗具有以下特性的非空二叉树: 1. 若左子树 ...

  9. NYIST 677 碟战

    碟战时间限制:2000 ms | 内存限制:65535 KB难度:4 描述知己知彼,百战不殆!在战争中如果被敌人掌握了自己的机密,失败是必然的.K国在一场战争中屡屡失败,就想到自己的某些城市可能会有敌 ...

  10. ASP.NET-RedirectToAction只能使用get方法

    两个同名Action共同使用return View() return RedirectToAction("test", new { ls = list.Fct_OrderList ...