欧拉定理不要忘记!!

#include <bits/stdc++.h>
#define N 100000
#define ll long long
#define ull unsigned long long
#define setIO(s) freopen(s".in","r",stdin)
using namespace std;
int array[10]={2,3,4679,35617};
ll mult(ll x,ll y,ll mod)
{
ll tmp=(long double)x/mod*y;
return ((ull)x*y-tmp*mod+mod)%mod;
}
ll qpow(ll base,ll k,ll mod)
{
ll tmp=1;
for(;k;k>>=1,base=mult(base,base,mod)) if(k&1) tmp=mult(tmp,base,mod);
return tmp;
}
struct Lucas
{
int mod;
int fac[N];
ll inv(ll x)
{
return qpow(fac[x],mod-2,mod);
}
void init(int p)
{
mod=p;
fac[0]=1;
for(int i=1;i<=mod;++i) fac[i]=(ll)fac[i-1]*i%mod; // inv[i]=qpow(fac[i],mod-2,mod);
}
ll C(int n,int m)
{
if(m==0) return 1;
if(n<m) return 0;
return (ll)(1ll*fac[n]*inv(m)%mod*inv(n-m)%mod)%mod;
}
ll solve(int n,int m)
{
if(m==0) return 1;
return (solve(n/mod,m/mod)*C(n%mod,m%mod))%mod;
}
}comb;
struct CRT
{
int n;
ll arr[N],brr[N];
ll exgcd(ll a,ll b,ll &x,ll &y)
{
if(!b)
{
x=1,y=0;
return a;
}
ll gcd=exgcd(b,a%b,x,y),tmp=x;
x=y,y=tmp-a/b*y;
return gcd;
}
ll ExCRT()
{
ll ans=arr[1],M=brr[1];
for(int i=2;i<=n;++i)
{
ll a=M,b=brr[i],c=arr[i]-ans,gcd,x,y;
gcd=exgcd(a,b,x,y),b=abs(b/gcd);
x=x*(c/gcd),x=(x%b+b)%b;
ans+=M*x;
M*=brr[i]/__gcd(brr[i],M);
ans=(ans%M+M)%M;
}
return ans;
}
}crt;
int main()
{
// setIO("input");
int i,j;
ll nn,gg,re,tmp,h;
scanf("%lld%lld",&nn,&gg);
if(gg%(999911659)==0)
{
printf("0\n");
return 0;
}
for(i=0;i<4;++i)
{
comb.init(array[i]),re=0,h=nn;
for(j=1;j*j<nn;++j)
{
if(nn%j==0)
{
re=(re+comb.solve((int)nn,j))%array[i];
re=(re+comb.solve((int)nn,nn/j))%array[i];
}
}
if(j*j==nn) re=(re+comb.solve((int)nn,j))%array[i];
crt.arr[i+1]=re;
crt.brr[i+1]=(ll)array[i];
}
crt.n=4;
tmp=crt.ExCRT();
printf("%lld\n",qpow(gg,tmp,999911659));
return 0;
}

  

BZOJ 1951: [Sdoi2010]古代猪文 ExCRT+欧拉定理+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. BZOJ 1951: [Sdoi2010]古代猪文 [Lucas定理 中国剩余定理]

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

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

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

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

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

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

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

  6. BZOJ 1951 [SDOI2010]古代猪文 (组合数学+欧拉降幂+中国剩余定理)

    题目大意:求$G^{\sum_{m|n} C_{n}^{m}}\;mod\;999911659\;$的值$(n,g<=10^{9})$ 并没有想到欧拉定理.. 999911659是一个质数,所以 ...

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

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

  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. Firebase Chat (firebase 实现web聊天室)

    基于firebase + cloud Function 实现web聊天(demo版) 知识点: 使用Firebase SDK创建Google Cloud功能. 触发云功能基于Auth,云存储和Clou ...

  2. spark算子篇-repartition and coalesce

    我们知道 RDD 是分区的,但有时候我们需要重新设置分区数量,增大还是减少需要结合实际场景,还有可以通过设置 RDD 分区数来指定生成的文件的数量 重新分区有两种方法:repartition and ...

  3. nodes.js详细安装

    nodes.js详细安装 Node.js 本章节我们将向大家介绍在window和Linux上安装Node.js的方法. 本安装教程以Node.js v4.4.3 LTS(长期支持版本)版本为例. No ...

  4. 向PHP使用Post方式上传文件

    欢迎访问我的个人博客,获取更多有用的东西 链接一 链接二 也可以关注我的微信订阅号:CN丶Moti 1.post-file.html form表单提交方式一定要是post,而且添加属性enctype= ...

  5. global.css

    global.css /* 页面元素初始化和常用样式定义-start */ /*======== 全局 ========*/ body, div, dl, dt, dd, ul, ol, li, h1 ...

  6. js之数据类型(对象类型——构造器对象——数组2)

    一.数组空位与undefined 数组空位:数组的某一个位置没有任何值 产生空位的原因:数组中两个逗号之间不放任何值:用new Array()的方法,参数里是个数字:通过一个不存在的下标去增加数组:增 ...

  7. Matplotlib 随机漫步图

    import matplotlib.pyplot as plt from random import choice class Randomwalk(): def __init__(self,num_ ...

  8. Photoshop从入门到精通所有视频教程(43G)以及素材资料免费拿

    包含了Photoshop从入门到精通所有需要了解的视频教程资料,并且包含了大量的P图素材. 资料获取方式,关注公总号RaoRao1994,查看往期精彩-所有文章,即可获取资源下载链接 更多资源获取,请 ...

  9. JavaMaven【五、Maven集成Eclipse使用】

    创建Maven项目 右键->new->other(Ctrl+n)->Maven Project->quickStart(catalog) 执行指令 右键->Run As- ...

  10. c++11 移动语义move semantics

    performance, expensive object copies move semantics, temporary objects implemented with rvalue refer ...