bOn the task z-stepen why do i get wrong result when i checked it a couple of times and it's correct
here's my code
program zstepen;
var s,o,p,z:longint;
i,m:integer;
begin
readln(o,s,m);
z:=1;
for i:=1 to s do
z:=z*o;
p:=z mod m;
writeln(p);
end.
kI have the same problem too
N@bojana92
Your should try to find a better solution. Imagine calculating 2000000000^2000000000 : it would take ages !
nYea, that's too big number, and you can't register it in memory in ordinary way. You need to ouput the number O^S with modulo M. So a*b mod M = (a mod M)*(b mod m). But you will still have Time Limit Exceeded. Try something smarter.
Hint:
a^b = (a^{b/2})^2 if b is an even number
a^b = (a^{b / 2})^2*a if b is an odd number
I think this will help you to solve the problem...
mprogram zstepen;
var s,o,p,z:longint;
i,m:integer;
begin
readln(o,s,m);
z:=1;
for i:=1 to s do
z:=z*o mod m;
p:=z mod m;
writeln(p);
end.
i think it will work
Dcan somebody please check my code? I got all wrong results. Thanks in advance.
bmateo123 the code works on some tests by the way i figured it out
m@Diabolic:
i think it will be work
#include <iostream>
using namespace std;
int main() {
long long int o,s,g=1;
int m;
cin>>o>>s>>m;
for(int i=0;i<s/2;i++)
{
g=(g%m)*(o%m);
}
cout<<g;
return 0;
}
it this code wont work i think that nikola's idea is great