#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int a[4]={2,3,4679,35617};
int p[36000],b[4],n,g,ans,i,j,x,y,mod=999911658;
int power(int a,int b){//快速幂
int c=1;
for(;b;b>>=1){
if(b&1) c=(ll)c*a%mod;
a=(ll)a*a%mod;
}
return c;
}
void exgcd(int a,int b,int &x,int &y){
if(!b) {x=1,y=0; return;}
exgcd(b,a%b,x,y);
int z=x; x=y; y=z-y*(a/b);
}
int inv(int a,int p){//求乘法逆元
int x,y;
exgcd(a,p,x,y);
return (x%p+p)%p;
}
int calc(int x,int mod){//求C(n,x)%mod的值
int ans=1,y,a,b;
for(y=n;x;x/=mod,y/=mod){//lucas定理
a=x%mod,b=y%mod;
ans=(ll)ans*p[b]%mod*inv(p[a],mod)%mod*inv(b<a?0:p[b-a],mod)%mod;//p[n]是n的阶乘取模mod的结果。
}
return ans;
}
int main(){
cin>>n>>g;
g%=mod+1;
if(!g) {cout<<"0\n"; return 0;}
for(p[0]=i=1;i<=a[3];i++) p[i]=(ll)p[i-1]*i%mod;//预处理n的阶乘(处理到取模数就可以了)
for(i=1;i*i<=n;i++)
if(n%i==0){
for(j=0;j<4;j++) b[j]=(b[j]+calc(i,a[j]))%a[j];
if(i*i!=n)
for(j=0;j<4;j++) b[j]=(b[j]+calc(n/i,a[j]))%a[j];
}
for(i=0;i<4;i++){
exgcd(mod/a[i],a[i],x,y);
ans=(ans+(ll)x*(mod/a[i])%mod*b[i])%mod;
}
ans=(ans+mod)%mod,mod++;
ans=power(g,ans);
cout<<ans<<endl;
return 0;
}

  

最新文章

  1. yotaku的开发日志(1)
  2. Pointcut is malformed: Pointcut is not well-formed: expecting &#39;identifier&#39; at character position 0 ^
  3. 更新centos curl
  4. MyEclipse/Eclipse中修改包的显示结构
  5. swift流行UI库(github)
  6. hello,world!
  7. 科学计算器的Java实现
  8. while MyJob = &#39;程序员&#39; do --- 序
  9. careercup-链表 2.2
  10. python用法——Mixin
  11. 标准I/O缓冲:全缓冲、行缓冲、无缓冲
  12. iOS Button 上文字图片位置的设置
  13. ios-微信支付登录分享-notification通知
  14. PHP 5.3中的命名空间使用方法
  15. 2018-2019-2 网络对抗技术 20165333 Exp4 恶意代码分析
  16. pyhanlp 文本聚类详细介绍
  17. JavaScript中十种一步拷贝数组的方法
  18. ecCodes 学习 利用ecCodes fortran90 api对GRIB文件进行读写
  19. 前端 CDNJS 库及 Google Fonts、Ajax 和 Gravatar 国内加速服务
  20. Istio微服务架构初试

热门文章

  1. if (i%4 ==0 ) 逻辑的魅力 在于 这里
  2. mysql 视图、触发器、事物、存储过程、函数
  3. 在C#中,Json的序列化和反序列化的几种方式
  4. New Concept English three (58)
  5. Rational Rose 2003 下载、破解及安装方法(图文)
  6. PHP Smarty template for website
  7. JQuery 提供了两种方式来阻止事件冒泡。
  8. UVA - 1608 Non-boring sequences (分治,中途相遇法)
  9. HDU - 5126 stars (CDQ分治)
  10. Unity3d-WWW实现图片资源显示以及保存和本地加载