1951: [Sdoi2010]古代猪文
1951: [Sdoi2010]古代猪文
Time Limit: 1 Sec Memory Limit: 64 MB
Submit: 2171 Solved: 904
[Submit][Status][Discuss]
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。
Source

#include<cstdio>
using namespace std;
typedef long long ll;
const int P=;
int M[],t[]={,,,};
int N,G,fac[][(int)4e4];
int fpow(ll a,ll p,ll mod){
ll res=;
for(;p;p>>=,a=a*a%mod) if(p&) res=res*a%mod;
return res;
}
int C(int n,int m,int x){
if(m>n) return ;
return fac[x][n]*fpow(fac[x][n-m]*fac[x][m],t[x]-,t[x])%t[x];
}
void exgcd(int a,int b,ll &x,ll &y){
if(!b){x=;y=;return ;}
exgcd(b,a%b,x,y);
ll t=x;x=y;y=t-a/b*y;
}
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];
}
ll CRT(){
ll x0,y0,ans=,Z=P-;
for(int i=;i<;i++){
int d=Z/t[i];
exgcd(d,t[i],x0,y0);
ans=(ans+d*x0*M[i])%Z;
}
while(ans<=) ans+=Z;
return ans;
}
int main(){
scanf("%d%d",&N,&G);
if(N==G){puts("");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=,tmp;i*i<=N;i++){
if(N%i==){
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",fpow(G,CRT(),P));
return ;
}
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,N,求: $$ans=G^{\sum_{i|n}\binom{n}{i}}\ \mod\ \ p$$ 1<=N,G<=10^9,p=999911659. [算法]欧拉定理+ ...
- bzoj 1951: [Sdoi2010]古代猪文 【中国剩余定理+欧拉定理+组合数学+卢卡斯定理】
首先化简,题目要求的是 \[ G^{\sum_{i|n}C_{n}^{i}}\%p \] 对于乘方形式快速幂就行了,因为p是质数,所以可以用欧拉定理 \[ G^{\sum_{i|n}C_{n}^{i} ...
随机推荐
- noip模拟赛:电话时间[字符串]
[问题描述] 某人总是花很多时间给父母打电话.有一次他记录了打电话的开始时间和结束时刻t1和t2,请你帮他算算此次通话一共用了多少秒.又有一次,他记录了打电话的开始时刻t1和通话的时间长度len,请你 ...
- last error : SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate veri
今天在用搜狐提供的邮件群发系统的sdk,做发送邮件的测试时,提示: last error : SSL certificate problem, verify that the CA cert is O ...
- xcode5向APP store上传应用的时候注意点
最近我在向appstore 上传应用的时候遇到了各种问题,由于网上的一些教程都是很久以前写的了,现在发布网站有些改动,所以自己走了很多弯路,不多说了,自己记录下犯下的错误吧.我是按照这片博客操作的:点 ...
- ASP.NET WebAPI HTTPS
参照文档 http://southworks.com/blog/2014/06/16/enabling-ssl-client-certificates-in-asp-net-web-api/ 第一 ...
- 用c#实现与飞环语音卡的交互
现在很多企业都采用freeswitch搭建的软交换来实现通话,主要优势成本低吞吐量大,但是语音卡的通话质量还是瑞胜一筹. 去年有机会在朋友公司里帮忙开发与软交换交互的上层服务及接口,在开发过程中稍微研 ...
- thrift之默认传输类TTransportDefaults和虚拟传输类TVirtualTransport
默认传输类TTransportDefaults提供了抽象类TTransport的默认实现,实现了非虚拟的方法(*_virt) read(), readAll(), write(),borrow() a ...
- linux前四天学习笔记
以下是在linux培训机构所学的内容,感觉比较乱 MySQL学习笔记MySQL的安装 linux中的超级管理员rootaixocm vnc的退出: F8 MySQL的特点.优点:关系型开源.免费c++ ...
- convert.c:7:3: warning: incompatible implicit declaration of built-in function ‘printf’ [enabled by
产生这样的问题主要是因为你使用了某一个函数,却没有引入相应的头文件.这与java中其实是一样的. 例如:在java中,使用某一个工具类,就要导入相应的包.
- <Video> in HTML5
HTML5 提供了视频播放元素<video>用来显示播放特定格式的视屏. * <video> 所支持的视屏格式: Ogg, MPEG4, WebM *<video> ...
- Mybatis-Spring SqlSessionTemplate 源码解析
在使用Mybatis与Spring集成的时候我们用到了SqlSessionTemplate 这个类. <bean id="sqlSession" class="or ...