Friday, September 14, 2012

calculate 2008 ! mod 2011

we see that 2011 is a prime number

so as per wilson theorem http://en.wikipedia.org/wiki/Wilson%27s_…

2010! mod 2011 = - 1

as 2010 mod 2011 = - 1 so 2009! mod 2011 = 1

so 2008 ! mod 2011 = inverse(2009) mod 2011 = - (inverse 2 mod 2011)

you can compute inverse using extended euclid algorithm http://en.wikipedia.org/wiki/Extended_Eu…

but there is a short cut.

as 2 * 1006 = 1 mod 2011 so inverse 2 is 1006
so 2008 ! mod 2011 = - (inverse 2 mod 2011) = - 1006 mod 2011 = 1005

No comments: