Page 5 of 6
Re: TLE 374 Big MOd!
Posted: Fri Apr 06, 2012 2:13 pm
by john_cu_cse
whats wrong in my cod ..i am getting wrong answer
#include<stdio.h>
#include<stdio.h>
#include<math.h>
long BigMod(long b,long p,long m);
int main()
{
long B,P,M,T,ans;
while(scanf("%ld%ld%ld",&B,&P,&M)!=EOF)
{
ans=BigMod(B,P,M);
printf("\n\n");
printf("%ld",ans);
}
return 0;
}
long BigMod(long b,long p,long m)
{
long r;
if(p==0)
return 1;
else if(p%2==0)
{
r=BigMod(b,p/2,m);
return (r*r)%m;
}
else
return ((b%m)*BigMod(b,p-1,m))%m;
}
Re: TLE 374 Big MOd!
Posted: Sat Apr 07, 2012 12:45 am
by brianfry713
Change this:
printf("\n\n");
printf("%ld",ans);
to this:
printf("%ld\n",ans);
Re: TLE 374 Big MOd!
Posted: Sat Apr 07, 2012 6:08 pm
by john_cu_cse
Thanks...I got AC.
374 - Big Mod
Posted: Tue Jun 19, 2012 9:36 pm
by @ce
Re: 374 - Big Mod
Posted: Tue Jun 19, 2012 11:14 pm
by brianfry713
Always end your code with return 0;
Re: 374 - Big Mod
Posted: Thu Jun 21, 2012 6:27 pm
by @ce
Doesn't help...still RE

Re: 374 - Big Mod
Posted: Thu Jun 21, 2012 8:46 pm
by brianfry713
Try input:
2147483647
2147483647
46340
My AC code returns 13903 in less than 1/1000th of a second.
Re: 374 - Big Mod
Posted: Sat Dec 22, 2012 8:04 am
by @ce
Getting WA...test case plzz...anyone
Re: 374 - Big Mod
Posted: Sat Dec 29, 2012 11:01 pm
by brianfry713
Input:
0
0
1
AC output:
0
Re: 374 - Big Mod
Posted: Sun Dec 30, 2012 7:38 pm
by @ce
Thanks brianfry713...i got AC.
Re: 374 - Big Mod
Posted: Wed Jan 30, 2013 8:07 pm
by gr81
Help.. getting RE, my code is here...
http://ideone.com/o1Q6qf
Re: 374 - Big Mod
Posted: Wed Jan 30, 2013 11:11 pm
by brianfry713
Try input 1 0 1
Re: 374 - Big Mod
Posted: Sun Mar 03, 2013 6:50 am
by devilreborn
I am getting WA on this pascal code. Can anybody help?
Code: Select all
var
a,b,c:longint;
function pmod(a,b,c:longint):integer;
var
x:integer;
begin
if b = 0 then
pmod := 1 mod c;
if b = 1 then
pmod := a mod c;
if b > 1 then
begin
if (b mod 2) = 0 then
begin
x := pmod(a,b div 2,c);
pmod := (x*x) mod c;
end
else
pmod := (pmod(a,b-1,c) * (a mod c)) mod c;
end;
end;
begin
readln(a,b,c);
writeln(pmod(a,b,c));
end.
Re: 374 - Big Mod
Posted: Tue Mar 05, 2013 1:02 am
by brianfry713
There are 3 lines in the sample output.
Re: 374 - Big Mod
Posted: Tue Jun 25, 2013 2:45 am
by Yusif
getting wa