A little bit of modular arithmetic in C++:

int mul(int x, int y, int m) { return (((long long) x) * y) % m; }

int pow(int x, int y, int m){
 int ans = 1; int pwr = x; int ind = 1;
 while (y != 0){
  if ((y & ind) == ind) { ans = mul(ans, pwr, m); y -= ind; }
  pwr = mul(pwr, pwr, m); ind = ind * 2;
 }
 return ans;
}

Errors and Omissions Expected




On 1 Feb 2013, at 04:39, Rodgers Andati <[email protected]> wrote:

> 
> @upen, if you working with Java, look at biginteger data type. Google it up.
> 
> 
> On Fri, Feb 1, 2013 at 3:35 AM, kethireddy siddartha <[email protected]> 
> wrote:
> Hello All,
>     I am searching for an alogirthm or C code for "Game of Life" and Eden of 
> Garden. If you have any idea or material, please do e-mail me.
> 
> On Thu, Jan 31, 2013 at 4:44 PM, Joseph DeVincentis <[email protected]> wrote:
> I am not sure what this is for, but in problems that ask for something like 
> this, you usually only need x^y modulo m, or the last so many digits of the 
> number, which is equivalent. There are shortcuts to calculate this without 
> calculating all of x^y.
> 
> 
> On Thu, Jan 31, 2013 at 6:12 PM, upen <[email protected]> wrote:
> How to calculate the pow(x,y) if both x,y in range of 10^9
> i mean how to calculate (10^9)^(10^9)
> How to store the result.
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Google Code Jam" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit 
> https://groups.google.com/d/msg/google-code/-/c8jTvFRAdjcJ.
> For more options, visit https://groups.google.com/groups/opt_out.
>  
>  
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Google Code Jam" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> To post to this group, send email to [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.
>  
>  
> 
> 
> 
> -- 
> Thank you and regards
> Siddartha.K
> +91-9491821187 , +91-8374705241
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Google Code Jam" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> To post to this group, send email to [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.
>  
>  
> 
> 
> 
> -- 
> Rodgers Andati
> 3th year Student, University of Nairobi,
> Bsc Computer Science,
> Mobile: +254715795302
> Google+: https://plus.google.com/u/0/108569713792535094597/about
> Linked In : http://ke.linkedin.com/pub/rodgers-andati/54/73/758
> 
> 
> And in the end, it's not the years in your life that count. It's the life in 
> your years.
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Google Code Jam" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> To post to this group, send email to [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.
>  
>  

-- 
You received this message because you are subscribed to the Google Groups 
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to