QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#469237 | #6887. Data Generation | grass8cow | AC ✓ | 230ms | 3872kb | C++17 | 1002b | 2024-07-09 16:38:46 | 2024-07-09 16:38:46 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int mod=998244353;
#define ll long long
ll qpow(ll a,ll b){
ll c=1;
for(;b;b>>=1){
if(b&1)c=1ll*a*c%mod;
a=1ll*a*a%mod;
}
return c;
}
ll n,m;
struct qq{
int a[2][2];
};
qq operator * (const qq &a,const qq &b){
qq c;memset(c.a,0,sizeof(c.a));
for(int k=0;k<2;k++)for(int i=0;i<2;i++)for(int j=0;j<2;j++)
(c.a[i][j]+=1ll*a.a[i][k]*b.a[k][j]%mod)%=mod;
return c;
}
void sol(){
scanf("%lld%lld",&n,&m);n%=mod;
qq A,B;memset(A.a,0,sizeof(A.a));
memset(B.a,0,sizeof(B.a));
A.a[1][1]=((n-1)*(n-1)+1)%mod;
A.a[1][0]=((n-1)*2)%mod;
A.a[0][1]=2;
A.a[0][0]=(n*n-2)%mod;
B.a[0][1]=1;
for(ll e=m;e;e>>=1){
if(e&1)B=B*A;
A=A*A;
}
int inv = qpow(qpow(n * n % mod, mod - 2), m);
printf("%lld\n",(n%mod*B.a[0][0]%mod+mod)%mod * inv % mod);
}
int main(){
int T;scanf("%d",&T);while(T--)sol();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 230ms
memory: 3872kb
input:
100000 19491001 19491001 999999999449325353 939501148 400027352 999999998707619026 999999998353720210 999999999303057191 1879045722 1874448608 999999998385974740 1710466660 109045962 999999998020190078 999999998217418921 999999998898659805 999999999999986692 999999998389218199 351693073 2130408866 1...
output:
79256423 60176292 660407710 893892599 601021657 353145264 33871948 852325473 308290667 313185571 805837881 700368815 711096361 895992243 830757079 419158396 754661682 184055154 728055491 1 323104191 72240859 553717086 361196534 971355231 232530344 149284730 833553979 48731930 0 296123988 928795526 5...
result:
ok 100000 lines