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} ...
随机推荐
- Python Learing(二):Basic Image Processing 1
<写在前面> Basic image processing 1: 0.(以简单的曲线图为例)对于生成的图自定义外观,使用子图,多个数据集,标题,标签,交互式标注,图例: 1.生成散点图,直 ...
- 最短路模板[spfa][dijkstra+堆优化][floyd]
借bzoj1624练了一下模板(虽然正解只是floyd) spfa: #include <cstdio> #include <cstring> #include <alg ...
- Oracle常用操作
比较时间 select * from up_date where update < to_date('2007-09-07 00:00:00','yyyy-mm-dd hh24:mi:ss' ...
- Hive中抽取连续多天登录用户
昨天群上有人发个阿里的面试题,题目描述大概如下: 数据源:用户登录表,只有俩个字段,uid和dt 试用HQL抽取出连续登录了K天的用户uid 第一个想法就是直接用一个UDF解决,按uid分组,把dt收 ...
- Forms Authentication in ASP.NET MVC 4
原文:Forms Authentication in ASP.NET MVC 4 Contents: Introduction Implement a custom membership provid ...
- Oracle随机获取记录
, )) RANDOMNUM FROM DUAL) B ORDER BY B.RANDOMNUM
- Oracle查询错误分析:ORA-01791:不是SELECTed表达式
表结构如下: create table HH_BOOK_GOOD ( ID VARCHAR2(32) not null, BOOKID VARCHAR2(32) not null, GOODID VA ...
- linux下使用kpartx挂载虚拟文件系统
在linux中,如果映像文件(.img)含有分区表的话,那么用losetup这个程序来加载文件系统就有点力不从心了.因为losetup只能加载无分区的文件系统映像文件.不过有一个好东西配合losetu ...
- 三角形(Triangle)
三角形(Triangle) 问题 给出一个三角形,找出从顶部至底部的最小路径和.每一步你只能移动到下一行的邻接数字. 例如,给出如下三角形: [ [2], [3,4], [6,5,7], [4,1,8 ...
- solrcloud集群部署
Zookeeper安装 Zookeeper的安装和配置十分简单, 既可以配置成单机模式, 也可以配置成集群模式. 下面将分别进行介绍. 注意防火墙和selinux,关闭后进行如下配置,由于是Java写 ...