传送门
乱逆元。
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<map>
#include<queue>
#include<math.h>
using namespace std;
#define ll long long
#define mod 4933ll
ll x[100010],y[100010],z[100010];
ll qpow(ll a, ll b)
{
ll ans = 1;
while(b)
{
if(b%2)ans *= a%mod,ans%=mod;
b/=2;
a = a%mod*a%mod;
a%=mod;
}
return ans%mod;
}
int main()
{
ll n,m,k,a,l;
cin>>n>>m>>k>>a>>l;
for(int i = 1; i <= k; i++)
{
cin>>x[i]>>y[i]>>z[i];
}
ll sum = 1;
ll ans = a%mod;
for(int i = 1; i <= k; i++)
{
if(x[i]==0)continue;
ll now = z[i]-y[i];
ll nowx = z[i];
ll p = __gcd(now,nowx);
now/=p;
nowx/=p;
sum = sum%mod*now%mod*qpow(nowx,mod-2)%mod;
sum%=mod;
}
cout<<(ans+sum)%mod<<endl;
}