374 - Big Mod
Moderator: Board moderators
-
- New poster
- Posts: 5
- Joined: Mon Mar 21, 2011 4:53 pm
Re: TLE 374 Big MOd!
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;
}
#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;
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: TLE 374 Big MOd!
Change this:
printf("\n\n");
printf("%ld",ans);
to this:
printf("%ld\n",ans);
printf("\n\n");
printf("%ld",ans);
to this:
printf("%ld\n",ans);
Check input and AC output for thousands of problems on uDebug!
-
- New poster
- Posts: 5
- Joined: Mon Mar 21, 2011 4:53 pm
Re: TLE 374 Big MOd!
Thanks...I got AC.
374 - Big Mod
Getting RE...plzz help
Code: Select all
Removed
Last edited by @ce on Sat Dec 22, 2012 8:05 am, edited 1 time in total.
-@ce
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 374 - Big Mod
Always end your code with return 0;
Check input and AC output for thousands of problems on uDebug!
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 374 - Big Mod
Try input:
2147483647
2147483647
46340
My AC code returns 13903 in less than 1/1000th of a second.
2147483647
2147483647
46340
My AC code returns 13903 in less than 1/1000th of a second.
Check input and AC output for thousands of problems on uDebug!
Re: 374 - Big Mod
Getting WA...test case plzz...anyone
Code: Select all
AC
Last edited by @ce on Sun Dec 30, 2012 7:41 pm, edited 1 time in total.
-@ce
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 374 - Big Mod
Input:
0
0
1
AC output:
0
0
0
1
AC output:
0
Check input and AC output for thousands of problems on uDebug!
Re: 374 - Big Mod
Help.. getting RE, my code is here...http://ideone.com/o1Q6qf
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
-
- New poster
- Posts: 1
- Joined: Sun Mar 03, 2013 6:46 am
Re: 374 - Big Mod
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.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 374 - Big Mod
There are 3 lines in the sample output.
Check input and AC output for thousands of problems on uDebug!
Re: 374 - Big Mod
Last edited by Yusif on Fri Jul 19, 2013 8:29 am, edited 1 time in total.