/*
古代猪文:Lucas定理+中国剩余定理
999911658=2*3*4679*35617
Lucas定理:(m,n)=(sp,tp)(r,q) %p
中国剩余定理:x=sum{si*Mi*ti}+km
先求出sum{C(d,n)}%p[i]=a[i]
*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 999911659
#define maxn 100005
ll m[]={,,,};
ll f[][maxn],a[],d[maxn];
ll exgcd(ll a,ll b,ll &x,ll &y){
if(b==){x=,y=;return a;}
ll d=exgcd(b,a%b,x,y);
ll z=x;x=y,y=z-a/b*y;
return d;
}
ll inv(ll a,ll Mod){
ll x,y;
exgcd(a,Mod,x,y);
return (x+Mod)%Mod;
}
ll C(int i,ll n,ll k,ll p){return f[i][n]*inv(f[i][k]*f[i][n-k]%p,p)%p;}
ll lucas(int i,ll n,ll k,ll p){
int res=;
while(n&&k){
res=res*C(i,n%p,k%p,p)%p;
if(res==)return ;
n/=p,k/=p;
}
return res;
}
ll Pow(ll x,ll n,ll Mod){
ll res=;
while(n){
if(n%)res=res*x%Mod;
n>>=;x=x*x%Mod;
}
return res;
}
ll china(int n,ll a[],ll m[]){
ll M=,res=;
for(int i=;i<n;i++)M*=m[i];
for(int i=;i<n;i++){
ll w=M/m[i],x,y;
exgcd(w,m[i],x,y);
res=(res+x*w*a[i])%M;
}
return (res+M)%M;
} int main(){
ll n,g;
cin>>n>>g;
if(g==mod){puts("");return ;}
int tot=;
for(int i=;i*i<=n;i++)
if(n%i==){//求n的所有质因子
if(i*i==n)d[tot++]=i;
else d[tot++]=i,d[tot++]=n/i;
}
for(int i=;i<;i++){
f[i][]=;
for(int j=;j<m[i];j++)
f[i][j]=f[i][j-]*j%m[i];
}
for(int i=;i<tot;i++)
for(int j=;j<;j++)
a[j]=(a[j]+lucas(j,n,d[i],m[j]))%m[j];;
ll ans=china(,a,m);
cout<<Pow(g,ans,mod);
}

古代猪文:数论大集合:欧拉定理,exgcd,china,逆元,Lucas定理应用的更多相关文章

  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. 【bzoj1951】: [Sdoi2010]古代猪文 数论-中国剩余定理-Lucas定理

    [bzoj1951]: [Sdoi2010]古代猪文 因为999911659是个素数 欧拉定理得 然后指数上中国剩余定理 然后分别lucas定理就好了 注意G==P的时候的特判 /* http://w ...

  3. luogu 2480 古代猪文 数论合集(CRT+Lucas+qpow+逆元)

    一句话题意:G 的 sigma d|n  C(n d) 次幂  mod 999911659 (我好辣鸡呀还是不会mathjax) 分析: 1.利用欧拉定理简化模运算 ,将上方幂设为x,则x=原式mod ...

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

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

  5. bzoj1951 [Sdoi2010]古代猪文 ——数论综合

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1951 题意就是要求 G^( ∑(k|n) C(n,k) ) % p,用费马小定理处理指数,卢 ...

  6. P2480 [SDOI2010]古代猪文

    P2480 [SDOI2010]古代猪文 比较综合的一题 前置:Lucas 定理,crt 求的是: \[g^x\bmod 999911659,\text{其中}x=\sum_{d\mid n}\tbi ...

  7. BZOJ1951 古代猪文 【数论全家桶】

    BZOJ1951 古代猪文 题目链接: 题意: 计算\(g^{\sum_{k|n}(^n_k)}\%999911659\) \(n\le 10^9, g\le 10^9\) 题解: 首先,根据扩展欧拉 ...

  8. BZOJ-1951 古代猪文 (组合数取模Lucas+中国剩余定理+拓展欧几里得+快速幂)

    数论神题了吧算是 1951: [Sdoi2010]古代猪文 Time Limit: 1 Sec Memory Limit: 64 MB Submit: 1573 Solved: 650 [Submit ...

  9. 1951: [Sdoi2010]古代猪文

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

随机推荐

  1. vue 导航栏切换

    <template> <footer class="menu"> <router-link to="/" class=" ...

  2. 【tmos】如何在Interceptor拦截器中注入其他数据

    光是这样是获取不到weixinConfig内容的 public class WebLoginInterceptor implements HandlerInterceptor { @Autowired ...

  3. 微服务之Spring cloud

    微服务 Spring cloud Spring Cloud provides tools for developers to quickly build some of the common patt ...

  4. Java内存模型-final域的内存语义--没明白,预留以后继续理解

    https://www.cnblogs.com/yuanfy008/p/9349275.html 来自 Java并发编程(1)-Java内存模型

  5. nodejs -Promise

    创建一个 readFile.js,读取三个文件abc的内容并输出到控制台 var fs = require('fs') fs.readFile('./a.txt','utf-8',function ( ...

  6. Java 进制间的转换

    package com.touch.onlinedu; public class Test { public static void main(String[] args) { // 1 : 0001 ...

  7. html5离线记事本

    离线记事本 这是一个笔记应用,不需要联网,也不需要数据库,可以直接把数据储存在本地.方便易用! ^_^ <!DOCTYPE html>  <html>  <head> ...

  8. 设计模式C++学习笔记之七(AbstractFactory抽象工厂模式)

      抽象工厂,提供一个创建一系列相关或相互依赖对象的接口,而无需指定它们具体的类.对于工厂方法来说,抽象工厂可实现一系列产品的生产,抽象工厂更注重产品的组合. 看代码: 7.1.解释 main(),女 ...

  9. 用UDP实现聊天功能

    // SK003Dlg.cpp : implementation file //   #include "stdafx.h" #include "SK003.h" ...

  10. 效率较高的php下读取文本文件的代码

    主要用下面这两个方法fread和 fgets的区别大家需要注意下     fread :以字节位计算长度,按照指定的长度和次数读取数据,遇到结尾或完成指定长度读取后停止.  fgets :整行读取,遇 ...