374 - Big Mod

All about problems in Volume 3. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

john_cu_cse
New poster
Posts: 5
Joined: Mon Mar 21, 2011 4:53 pm

Re: TLE 374 Big MOd!

Post by john_cu_cse » Fri Apr 06, 2012 2:13 pm

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;
}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: TLE 374 Big MOd!

Post by brianfry713 » Sat Apr 07, 2012 12:45 am

Change this:
printf("\n\n");
printf("%ld",ans);
to this:
printf("%ld\n",ans);
Check input and AC output for thousands of problems on uDebug!

john_cu_cse
New poster
Posts: 5
Joined: Mon Mar 21, 2011 4:53 pm

Re: TLE 374 Big MOd!

Post by john_cu_cse » Sat Apr 07, 2012 6:08 pm

Thanks...I got AC.

User avatar
@ce
Learning poster
Posts: 71
Joined: Mon May 28, 2012 8:46 am
Location: Ranchi, India

374 - Big Mod

Post by @ce » Tue Jun 19, 2012 9:36 pm

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

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 374 - Big Mod

Post by brianfry713 » Tue Jun 19, 2012 11:14 pm

Always end your code with return 0;
Check input and AC output for thousands of problems on uDebug!

User avatar
@ce
Learning poster
Posts: 71
Joined: Mon May 28, 2012 8:46 am
Location: Ranchi, India

Re: 374 - Big Mod

Post by @ce » Thu Jun 21, 2012 6:27 pm

Doesn't help...still RE :(
-@ce

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 374 - Big Mod

Post by brianfry713 » Thu Jun 21, 2012 8:46 pm

Try input:
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!

User avatar
@ce
Learning poster
Posts: 71
Joined: Mon May 28, 2012 8:46 am
Location: Ranchi, India

Re: 374 - Big Mod

Post by @ce » Sat Dec 22, 2012 8:04 am

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

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 374 - Big Mod

Post by brianfry713 » Sat Dec 29, 2012 11:01 pm

Input:
0
0
1

AC output:
0
Check input and AC output for thousands of problems on uDebug!

User avatar
@ce
Learning poster
Posts: 71
Joined: Mon May 28, 2012 8:46 am
Location: Ranchi, India

Re: 374 - Big Mod

Post by @ce » Sun Dec 30, 2012 7:38 pm

Thanks brianfry713...i got AC.
-@ce

gr81
New poster
Posts: 46
Joined: Wed Sep 26, 2012 7:52 pm

Re: 374 - Big Mod

Post by gr81 » Wed Jan 30, 2013 8:07 pm

Help.. getting RE, my code is here...http://ideone.com/o1Q6qf

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 374 - Big Mod

Post by brianfry713 » Wed Jan 30, 2013 11:11 pm

Try input 1 0 1
Check input and AC output for thousands of problems on uDebug!

devilreborn
New poster
Posts: 1
Joined: Sun Mar 03, 2013 6:46 am

Re: 374 - Big Mod

Post by devilreborn » Sun Mar 03, 2013 6:50 am

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.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 374 - Big Mod

Post by brianfry713 » Tue Mar 05, 2013 1:02 am

There are 3 lines in the sample output.
Check input and AC output for thousands of problems on uDebug!

Yusif
New poster
Posts: 27
Joined: Tue Jun 25, 2013 2:24 am

Re: 374 - Big Mod

Post by Yusif » Tue Jun 25, 2013 2:45 am

getting wa :(

Code: Select all

ac
Last edited by Yusif on Fri Jul 19, 2013 8:29 am, edited 1 time in total.

Post Reply

Return to “Volume 3 (300-399)”