Re: [algogeeks] [SPOJ] ZSUM

2011-10-20 Thread Wasif Hossain
Just a MINOR change.
please change the RED line(I've marked it below) in your code by the
following line:
*return (x*((z*z)%MOD))%MOD;*
and enjoy an *ACCEPTED *verdict.*
*

*Wasif Hossain**
*
B.Sc. Student of Final Semester,
Computer Science and Engineering(CSE),
Bangladesh University of Engineering and Technology(BUET),
Dhaka-1000
Bangladesh.

On Thu, Oct 6, 2011 at 1:13 AM, hashd kirandandupr...@gmail.com wrote:

 I'm getting WA on the question : ZSUM-SPOJhttps://www.spoj.pl/problems/ZSUM/

 Here is my code: Let me know if you can find the problem with the code


 #includecstdio
 #define MOD 1007

 typedef unsigned long long u64;
 using namespace std;

 u64 modExp(u64 x, u64 y){
 if(x==0)
 return 0;

 if(y==0)
 return 1;

 u64 z = modExp(x,y/2);

 if(y%2==0)
 return (z*z)%MOD;
 else
 *return (x*z*z)%MOD;*
 }

 int main(){
 u64 n, k; scanf(%llu%llu,n,k);
 while(nk){
 u64 ans = 0;

 if(n0)
 ans = (2*modExp(n-1,k) + modExp(n,k) + 2*modExp(n-1,n-1) +
 modExp(n,n))%MOD;

 printf(%llu\n,ans);
 scanf(%llu%llu,n,k);
 }

 return 0;
 }

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To view this discussion on the web visit
 https://groups.google.com/d/msg/algogeeks/-/p6j7nmaEUb4J.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: why we can not swap values using macro?

2011-10-19 Thread Wasif Hossain
@prasad jondhale: +1

Thanx.

Wasif Hossain
Final Semester Student,
Computer Science and Engineering(CSE),
Bangladesh University of Engineering and Technology(BUET)
Dhaka, Bangladesh.

On Wed, Oct 12, 2011 at 3:47 AM, prasad jondhale
jondhale.pra...@gmail.comwrote:

 hey man u have made a very silly mistakeyou have swaped only pointers
 not values.
 #includestdio.h
 #define swap(a,b,c) c t;t=a,a=b,b=t;
 main()
 {
 float x=10,y=20;
 float *p,*q;
 p=x,q=y;
 swap(p,q,float *);
 printf(%f %f\n,*p,*q);
 }

 gives result 20.00  10.00
  if want to change values of x and y then do
 *#define swap(a,b,c) c t;*t=*a,*a=*b,*b=*t;*
 *
 *
 *you can check your preprocessed output in linux by using -E option*
 *example:gcc -E pgm.c*

 On Mon, Oct 10, 2011 at 10:19 PM, sravanreddy001 sravanreddy...@gmail.com
  wrote:

 The swap is happenning between the p  q pointers,

 https://ideone.com/4MdX4

 p points to y, q points to x after swap.


 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To view this discussion on the web visit
 https://groups.google.com/d/msg/algogeeks/-/XvbyN8ajVEUJ.

 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --

 Thanks  Regards
 Prasad Y.Jondhale
 M.Tech(software engg.),
 Delhi College Of Engineering,
 Main Bawana road,Delhi-110042
 Ph-09540208001

  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] IVY comptech????

2011-10-07 Thread Wasif Hossain
Humble query to Admin: Is this question still relevant to this group by now
when interview-street is running properly?

On Thu, Oct 6, 2011 at 2:26 AM, htross htb...@gmail.com wrote:

 Does anybody know what kind of questions are asked in ivy comptech???
 ''

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.



-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Algo for in-place Stack Reversal.

2011-10-07 Thread Wasif Hossain
@Ankur: +1

On Fri, Oct 7, 2011 at 8:44 PM, Ankur Garg ankurga...@gmail.com wrote:

 To do inplace stack reversal u need a mechanism by which u can transfer the
 first node to last of the stack  making sure u have count of other nodes
 here

 Say u have stack

 5- top
 4
 3
 2
 1

 The answer should generate the stack as
 1-top
 2
 3
 4
 5
 This give hints to recursion . A normal recursive func willlook like

 InplaceReverse(stackints){
if(s.empty()) return;
temp=s.top();
s.pop();
InplaceReverse(s);
 }

 Now if one had to  print the stack nodes from bottom to top this would have
 helped as we get to bottom of stack.But we need a storing mechanism so may
 be one more recursive function can help so that we can pop the nodes first
 and then insert the top node

 Say the stack at a pt of time is
 1-top
 2

 Then to insert 3 at bottom we shud have some mechanism which can store
 values 1 and 2

 So u pop 1 and pop 2  ..Insert 2 and then Insert 1
 1- top
 2
 3

 Only way to achieve this without using extra space is another recursion .So
  I write a helper func which can help me here to achieve this. I call this
 helper Func as something like ReverseHelper and push the temp variable to it
 .

 So

 InplaceReverse(stackints){
if(s.empty()) return;
temp=s.top();
s.pop();
InplaceReverse(s);
ReverseHelper(s,temp);
 }
 ReverseHelper(stackints,int val){
  if(s.empty()) {
   s. push(val);
  return;
  }
 temp = s.pop();
ReverseHelper(s,val);
   s.push(temp);
 }

 Remember to pass stack as reference

 Regards
 Ankur

 }




 On Fri, Oct 7, 2011 at 7:54 PM, sravanreddy001 
 sravanreddy...@gmail.comwrote:

 in place means:

 use constant extra space

 in simple terms O(1) space

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To view this discussion on the web visit
 https://groups.google.com/d/msg/algogeeks/-/nDVS4k7fF34J.

 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.