1 条题解
-
-2
简单的题,只要快速幂和乘法逆元。要开O2!!! 代码:
#include<bits/stdc++.h> using namespace std; const unsigned long long MOD=998244353;//模数 unsigned long long sumjc=1,sumin=1;//阶乘 unsigned long long f(unsigned long long x,unsigned long long y){ //公约数 if (y==0){ return x; } return f(y,x%y)%MOD; } void jc(){//计算阶乘 sumjc=(sumin*sumjc)%MOD; sumin++; } unsigned long long Pow(unsigned long long a, unsigned long long b) { //快速幂 unsigned long long res = 1; while (b > 0) { if (b & 1) res = (res * a)%MOD; a = (a * a)%MOD; b >>= 1; } return res; } unsigned long long inv(unsigned long long a, unsigned long long p) {//乘法逆元 return Pow(a,p-2,p); } int main(){ freopen("math.in","r",stdin);//文件输入 freopen("math.out","w",stdout);//文件输出 unsigned long long n,k,abcd; cin>>n>>k; unsigned long long fs[2]={0,1},fs1[2]; for (unsigned int i=1;i<=n;i++){ memset(0,fs1,sizeof fs1); fs1[0]=sumjc; fs1[1]=Pow(i,k); //加法 fs[0]=(fs[0]*fs1[1]+fs[1]*fs1[0])%MOD; fs[1]=(fs[1]*fs1[1])%MOD; } //约分 abcd=f(fs[0],fs[1]); fs[0]=fs[0]/abcd%MOD; fs[1]=fs[1]/abcd%MOD; cout<<(fs[0]*inv(fs[1],MOD))%MOD;//计算逆元 return 0; }
- 1
信息
- ID
- 193
- 时间
- 3000ms
- 内存
- 512MiB
- 难度
- 9
- 标签
- (无)
- 递交数
- 111
- 已通过
- 10
- 上传者