Long long division.

Revision en1, by Imtiaz.axi, 2024-02-19 10:41:32

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?  

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en6 English Imtiaz.axi 2024-02-19 10:52:36 2 Tiny change: 'ill same\n~~~~~\n#' -> 'ill same\n\n~~~~~\n#'
en5 English Imtiaz.axi 2024-02-19 10:52:09 50
en4 English Imtiaz.axi 2024-02-19 10:46:15 1 Tiny change: 'e if(S[i]='R'){\n ' -> 'e if(S[i]=='R'){\n '
en3 English Imtiaz.axi 2024-02-19 10:45:14 15 Tiny change: '57 or any two digit number do' -> '57 or any small type number do'
en2 English Imtiaz.axi 2024-02-19 10:43:50 26
en1 English Imtiaz.axi 2024-02-19 10:41:32 1401 Initial revision (published)