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} ...
随机推荐
- memcpy的实现
memcpy的实现看起来貌似比较简单,但是也是有注意的地方! void *memcpy(void *dst, const void *src, size_t size) { //check argum ...
- Jackson 格式化日期问题
Jackson 默认是转成timestamps形式的,如何使用自己需要的类型, 解决办法: 1.在实体字段上使用@JsonFormat注解格式化日期 @JsonFormat(locale=" ...
- [转]iOS Tutorial – Dumping the Application Heap from Memory
Source:https://blog.netspi.com/ios-tutorial-dumping-the-application-heap-from-memory/ An essential ...
- 冒泡动画按钮的简单实现(使用CSS3)
冒泡动画按钮的简单实现(使用CSS3) 原始的参考文章是 http://tutorialzine.com/2010/10/css3-animated-bubble-buttons/ ,基本原理是利用了 ...
- 记录下自己写的gulp打包脚本
var c = { rootPath: 'src',//项目文件夹 outputPath: 'output',//文件编译后的输出目录 revPath: 'manifest',//rev映射文件目录 ...
- Use weechat (IRC client) on OS X. MacBook Pro
Weechat is a console IRC client. It is opensource and very easy to use. I use weechat in my Linux PC ...
- 密码配置配置SSH免密码登陆
在本文中,我们主要介绍密码配置的内容,自我感觉有个不错的建议和大家分享下 我的用户名是master 1.安装ssh(若没安装的话) sudo apt-get install ssh 2.配置为可以免密 ...
- bios中断向量表
- es6笔记1^_^let、string、number、math
ECMAScript是一种由Ecma国际(前身为欧洲计算机制造商协会,英文名称是European Computer Manufacturers Association)通过ECMA-262标准化的脚本 ...
- 类xml数据格式解析
需要解析一种类xml的数据文件,数据格式1如下: <head> //文件头 <type>xtype</type> <condition> key1=va ...