【BZOJ 1951】 [Sdoi2010]古代猪文
Description
Input
Output
Sample Input
Sample Output
HINT
10%的数据中,1 <= N <= 50;
20%的数据中,1 <= N <= 1000;
40%的数据中,1 <= N <= 100000;
100%的数据中,1 <= G <= 1000000000,1 <= N <= 1000000000。

#include<cstdio>
#define ll long long
const int P=;
int t[]={,,,};
int fac[][],M[],G,N;
int pow(ll a,ll b,ll x){
ll ans=;
while (b>){
if (b&==) ans=(ans*a)%x;
b=b>>;a=(a*a)%x;
}
return ans;
} int C(int a,int b,int x){
if (b>a) return ;
return fac[x][a]*pow(fac[x][a-b]*fac[x][b],t[x]-,t[x])%t[x];
} int lucas(int a,int b,int x){
if(!b) return ;
return C(a%t[x],b%t[x],x)*lucas(a/t[x],b/t[x],x)%t[x];
} void exgcd(int a,int b,ll &x,ll &y){
if (b==){x=,y=;return;}
exgcd(b,a%b,x,y);
int t=x;x=y,y=t-(a/b)*y;
} ll CRT()
{
ll N=;
ll i,d,x0,y0,ans=;
for(i=;i<;i++)
N*=t[i];
for(i=;i<;i++)
{
d=N/t[i];
exgcd(d,t[i],x0,y0);
ans=(ans+d*x0*M[i])%N;
}
while(ans<= )
ans+=N;
return ans;
}
int main(){
scanf("%d%d",&N,&G);
if (G==P) {
printf("");
return ;
}
G%=P;
for (int i=;i<;i++){//这里求阶乘
fac[i][]=;
for (int j=;j<=t[i];j++) fac[i][j]=(fac[i][j-]*j)%t[i];
}
for (int i=;i*i<=N;i++){
if(N%i==){
int tmp=N/i;
for (int j=;j<;j++){
if (tmp!=i) M[j]=(M[j]+lucas(N,i,j))%t[j];
M[j]=(M[j]+lucas(N,tmp,j))%t[j];
}
}
}
printf("%d",pow(G,CRT(),P));
}
【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] ...
- 【刷题】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]古代猪文
#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\) 由费马小定理,可以先对次数化简,即求\( ...
- bzoj 1951: [Sdoi2010]古代猪文 【中国剩余定理+欧拉定理+组合数学+卢卡斯定理】
首先化简,题目要求的是 \[ G^{\sum_{i|n}C_{n}^{i}}\%p \] 对于乘方形式快速幂就行了,因为p是质数,所以可以用欧拉定理 \[ G^{\sum_{i|n}C_{n}^{i} ...
- BZOJ 1951 [SDOI2010]古代猪文 (组合数学+欧拉降幂+中国剩余定理)
题目大意:求$G^{\sum_{m|n} C_{n}^{m}}\;mod\;999911659\;$的值$(n,g<=10^{9})$ 并没有想到欧拉定理.. 999911659是一个质数,所以 ...
- BZOJ 1951: [Sdoi2010]古代猪文 ExCRT+欧拉定理+Lucas
欧拉定理不要忘记!! #include <bits/stdc++.h> #define N 100000 #define ll long long #define ull unsigned ...
随机推荐
- wince 位图的使用
操作位图的基本步骤: *创建位图句柄 *加载位图对象 *创建内存设备描述对象,将位图选入内存设备描述对象 *使用绘图函数进行图形绘制 *删除位图句柄 创建位图句柄并且加载位图对象: *位图句柄 HBI ...
- CMS垃圾回收与G1垃圾回收
CMS垃圾回收与G1垃圾回收的比较请参见:http://colobu.com/2015/04/14/G1-Getting-Started/
- poj 1741 树的分治
思路:这题我是看 漆子超<分治算法在树的路径问题中的应用>写的. 附代码: #include<iostream> #include<cstring> #includ ...
- cent0s7 显卡驱动导致重启黑屏
由于 CentOS7.0 版本与前面的 CentOS6.5 及之前的版本的模式变更方法有很大 的不同,以前的版本中我们可以在vi /etc/inittab 文件中将id:5:initdefault 更 ...
- ubuntu qt :-1: error cannot find lgl
安装package "libgl1-mesa-dev": sudo apt-get install libgl1-mesa-dev 参考文献: Qt: can't find -lG ...
- SharePoint 2010 获取列表全部定义方法
http://spf06/_vti_bin/owssvr.dll?Cmd=ExportList&List=%7B220128F0-6084-45B3-9942-C29B3AF6663C%7D ...
- jquery jsonp实现跨域
html代码: $("#testJsonp").click(function(){ $.ajax({ url: "http://www.test.cc/1.php&quo ...
- MVC中提示错误:从客户端中检测到有潜在危险的 Request.Form 值的详细解决方法
今天往MVC中加入了一个富文本编辑框,在提交信息的时候报了如下的错误:从客户端(Content="<EM ><STRONG ><U >这是测试这...&q ...
- 转 Android 4.0后,自定义Title报错 You cannot combine custom titles with other title feature
自定义Titlebar时为了避免冲突 需要修改:AndroidManifest.xml android:theme="@style/mystyle" styles.xml文件中 ...
- 北大ACM(POJ1753-Flip Game)
Question:http://poj.org/problem?id=1753 问题点:穷举. #include <iostream> using namespace std; ][];/ ...