Chef and subsegments(CHMOD) i have posted the code , logic is quite correct and sample test cases passed ,but i am not getting why it gives wrong answer...Please Help!

#include<bits/stdc++.h>
using namespace std;
#define endl “\n”
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define vi vector
#define pb push_back
#define F first
#define S second
#define all(v) (v).begin(),(v).end()
#define pii pair<ll,ll>
#define vii vector
#define MOD 1000000007LL

int binpow(int a,int b,int m) // fast modular multiplication
{
if(b==0)return 1;
int res=binpow(a, b/2,m);
res = (resres)%m;
if(b%2){
res = (res
a)%m;
}
return res%m;
}

signed main()
{
FIO;
ll n,a,t,l,r,m;
cin>>n;
int arr[n][101]={{0}}; //storing number ocuurence of each prime factor for the given number
for(int i=0;i<n;i++)
{
cin>>a;
for(int j=2;j*j<=a;j++)//calculating prime factor
{

        while(a%j==0)
        {
            arr[i][j]++; //incrementing number of occurences
            a/=j;
        }
    }
    if(a!=1)
    arr[i][a]++;
}
for(int i=1;i<n;i++)           // taking prefix sums of number of occurences of prime factors in range upto 100
{
    for(int j=0;j<101;j++)
    arr[i][j]+=arr[i-1][j];
}

// arr[i][j] is storing prefix sums of number of occurences of prime factors

cin>>t;
while(t--)
{
    cin>>l>>r>>m;int ans=1;
    for(int i=1;i<=97;i++)
    {
        if(l==1)
        {
            ans=(ans*binpow(i,arr[r-1][i],m))%m;
        }
        else
        {
            ans=(ans*binpow(i,arr[r-1][i]-arr[l-2][i],m))%m;
        }
    }
    cout<<ans%m<<endl;
}

}