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

×

Problem in CHMOD question !!

I have used precalculation technique . For ex. let 1 2 3 4 5 be array . Then through precomputation i have made another array . 1 2 6 24 120 . After that in order to cal any query it is :- arra[m]/arr[l-1] where l is lower rage and m is upper .. Is my approach wrong.. getting WA many times Could someone help me out. Solution is :- http://www.codechef.com/viewsolution/6845308

asked 08 May '15, 01:31

ritwikenator's gravatar image

2★ritwikenator
4615
accept rate: 16%


Read the constraints again.

A[i]<=100;

If all elements of the array are 100, the product of N such elements of the array will be:

100X100X100...100(N times)=(100)^N

This will quickly overflow for large values of N as maximum value of long long int is 10^18. Therefore you need to implement multiplication between two numbers by adding their prime powers and then calculating (a^b)%c using fast squaring.

link

answered 08 May '15, 07:24

ironmandhruv's gravatar image

4★ironmandhruv
333239
accept rate: 20%

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:

×2
×1

question asked: 08 May '15, 01:31

question was seen: 312 times

last updated: 08 May '15, 07:24

Related questions