I am getting wrong answer please help me fix the code

#include<bits/stdc++.h>
using namespace std;
#define endl “\n”
#define sd(val) scanf("%d",&val)
#define ss(val) scanf("%s",&val)
#define sl(val) scanf("%lld",&val)
#define all(v) v.begin(),v.end()
#define PB push_back
#define MP make_pair
#define FF first
#define SS second
#define ll long long int
#define MOD 1000000007
#define clr(val) memset(val,0,sizeof(val))
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int multiply(ll x, ll y, ll p)
{
ll res = 1; // Initialize result

while (y > 0) 
{ 
	// If y is odd, multiply x with result 
	if (y & 1) 
		res = (res*x)%p; 

	// y must be even now 
	y = y>>1; // y = y/2 
	x = (x*x)%p; // Change x to x^2 
} 
return res; 

}

int main()
{
int t;
cin>>t;
while(t–)
{
ll a,n,p;
cin>>a>>n>>p;ll ans=1;
for(int i=1;i<=n;i++)
{
ans=(ans*(multiply(a,i,p)))%p;
}
cout<<ans<<endl;
}
return 0;

}

@be10046.19 corrected (line 43) (you cant multiply as in multiplication pow of sum are added not multiplied . so you have to do a pow apow2 pow apow3…)
dont forget to hit like and mark resolved if cleared :smiley:

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.