why my code fail in many test case
#include
using namespace std;
int main() {
long long int x,y,z;
cin>>x>>y>>z;
int exp = 1;
for(int i = 1; i <=y;i++){
exp = exp*x;
}
int k = exp % z;
cout<<k;
}
and also correct my code
why my code fail in many test case
#include
using namespace std;
int main() {
long long int x,y,z;
cin>>x>>y>>z;
int exp = 1;
for(int i = 1; i <=y;i++){
exp = exp*x;
}
int k = exp % z;
cout<<k;
}
and also correct my code
@kshitiz.gzb
You should the modulo with z at every iteration rather than just at the end.
exp = (exp*x)%z;
Make this change and try again.
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.