You are not logged in. Please login at www.codechef.com to post your questions!

×

Chef and Pattern

hey guys , Can you please help me in proving that (k^(2^n))%MOD is equailvalent to (k^((2^n)%(MOD-1))%MOD? Thanks,

asked 22 Jan '15, 11:41

johri21's gravatar image

2★johri21
446137
accept rate: 12%

edited 22 Jan '15, 11:42


It comes from Fermat's Little theorem...

check this thread for proof : click here

link

answered 22 Jan '15, 12:22

grayhathacker's gravatar image

5★grayhathacker
3374514
accept rate: 0%

I tried the following, a = (2^n-3)%MOD [ n<=2 taken care manually]

ans = (k^a)%MOD; But it gives WA.. Why is that??

link

answered 22 Jan '15, 14:43

desh_er_bojha's gravatar image

0★desh_er_bojha
31
accept rate: 0%

If you look in closely a was infact at max 2^(1e9) so that large a value will not be taken care by any language(a will overflow, so you have to mod a then k^a%MOD) , so you had to use the formuale mentioned above in my post.

(22 Jan '15, 18:28) johri212★
toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×333
×15

question asked: 22 Jan '15, 11:41

question was seen: 1,285 times

last updated: 22 Jan '15, 18:28