In last div 3 round i had a problem for deviding a big nunmber with a small one. I am new to programming.
include<bits/stdc++.h>
define ll long long
define str string
define fori(i,a,N) for (int i=a;i<N;i++)
using namespace std; vector prefix(vector arr) { int n = arr.size(); vector ps(n); ps[0] = arr[0]; for (int i = 1; i < n; i++) { ps[i] = ps[i — 1] + arr[i]; } return ps; }
int main() { int t; cin>>t; while(t--){ int N,M; cin>>N>>M; vectorA(N); string S; ll x=1; for(int i=0;i<N;i++){ cin>>A[i]; x*=A[i]; } cin>>S; cout<<x%M<<" "; int l=0,r=N-1; fori(i,0,N-1){ if(S[i]=='L'){ x/=A[l]; l++; cout<<x%M<<" "; } else if(S[i]='R'){ x/=A[r]; r--; cout<<x%M<<" "; } } cout<<endl; }
} Here when the value of x becomes more than 10^20, dividing it with numbers like 34,57 or any two digit number doesnt give correct output.for that x%M is also comes wrong.what should i do? And also is the code logic correct? I know it will always bottle neck if inputs are big numbers. But for small numbers what do i have to modify?