You are not logged in. Please login at 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 :-

asked 08 May '15, 01:31

ritwikenator's gravatar image

accept rate: 16%

Read the constraints again.


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.


answered 08 May '15, 07:24

ironmandhruv's gravatar image

accept rate: 20%

toggle preview

Follow this question

By Email:

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



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "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:


question asked: 08 May '15, 01:31

question was seen: 312 times

last updated: 08 May '15, 07:24

Related questions