QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#577120 | #6887. Data Generation | JZYZ# | AC ✓ | 155ms | 3724kb | C++14 | 1.6kb | 2024-09-20 08:15:29 | 2024-09-20 08:15:31 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
template <typename T>inline void read(T &x)
{
x=0;char c=getchar();bool f=0;
for(;c<'0'||c>'9';c=getchar())f|=(c=='-');
for(;c>='0'&&c<='9';c=getchar())x=(x<<1)+(x<<3)+(c-'0');
x=(f?-x:x);
}
typedef long long LL;
const int mod = 998244353;
int Pow(int a,int b)
{
int res=1;
while(b)
{
if(b&1)res=1ll*res*a%mod;
a=1ll*a*a%mod;
b>>=1;
}
return res;
}
struct mat
{
int w[2][2];
};
mat operator *(mat A,mat B)
{
mat C;
for(int i=0;i<2;i++)
for(int j=0;j<2;j++)
{
C.w[i][j]=0;
for(int k=0;k<2;k++)
C.w[i][j]=(C.w[i][j]+1ll*A.w[i][k]*B.w[k][j]%mod)%mod;
}
return C;
}
mat Pow(mat A,LL B)
{
mat res;
for(int i=0;i<2;i++)
for(int j=0;j<2;j++)
res.w[i][j]=(i==j);
while(B)
{
if(B&1)res=res*A;
A=A*A;
B>>=1;
}
return res;
}
int main()
{
//freopen("Sum.in","r",stdin);
//freopen("Sum.out","w",stdout);
int T;
read(T);
while(T--)
{
LL n,m;
read(n);read(m);
int p=Pow(n%mod,mod-2);
mat F,T;
int x=(n%mod);
for(int i=0;i<2;i++)
for(int j=0;j<2;j++)
F.w[i][j]=T.w[i][j]=0;
T.w[0][1]=2ll*p%mod*p%mod;
T.w[1][0]=2ll*(x-1)*p%mod*p%mod;
T.w[1][1]=1ll*(1+1ll*(x-1)*(x-1)%mod)*p%mod*p%mod;
T.w[0][0]=(1ll*x*x%mod-2+mod)%mod*p%mod*p%mod;
F.w[0][1]=1;
F=F*Pow(T,m);
int ans=F.w[0][0];
printf("%lld\n",1ll*ans*x%mod);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 155ms
memory: 3724kb
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