×

# Corner case in What is the last digit?

 0 i dont know where my code fails.There must be any corner case.Please let me know where my code fails. thanks in advance... //question link http://www.codechef.com/status/CDM03/ //solution link http://ideone.com/7Y0SGE asked 31 Dec '14, 16:24 2★emin3m 62●9 accept rate: 3%

 1 Try these, 4 19 2000 18 2000 17 2000 16 2000  Using inbuilt power pow function for such large computations give erroneous results. Try some other logic(there exists an easy one by just finding the cycle of the last digit of a example: 8^any power, after how many computations we get 8 as the last digit of our answer again) or some other way for computing power. There exists a logn method also. You may like seeing here.. answered 31 Dec '14, 16:40 3★damn_me 2.6k●2●13●36 accept rate: 24% Thanks a ton.. :) (31 Dec '14, 16:53) emin3m2★
 1 You are using the pow function which is creating problems.The range of the answer of a^b is very large and int cannot hold such large (even long long int cannot hold such numbers). You should try to calculate just the last digit not the whole answer. Check here your code is giving wrong answer. answered 31 Dec '14, 16:43 4★the65bit 1.1k●10●13●28 accept rate: 13% thanks for pointing out... thanks a lot (31 Dec '14, 16:54) emin3m2★ Welcome :) if it helps please upvote and accept it as correct answer ;) (31 Dec '14, 17:14) the65bit4★ i wish i could upvote but i have less reputation but i will certainly accept it as correct answer.. :) (31 Dec '14, 17:57) emin3m2★ Thanks I didn`t notice that!!! Happy Coding !!! (31 Dec '14, 18:46) the65bit4★
 1 As other's have told you where is your mistake,I won't be pointing it out again.But would rather like to give you a hint for solving this one.Try to store the result in an array.Now question arises How?? For that try to solve the Small Factorial problem first.This will help you build the concept of storing every digit of the result in an array. Do check the Tutorial if you face any trouble solving it.Here's link- Tutorial. After solving this,you'll surely be able to solve this one with ease. As you are storing every digit of the result in an array,it won't be difficult to print the last digit. Happy Coding!! answered 31 Dec '14, 19:24 206●1●2●9 accept rate: 9%
 0 Open the calculator program on your PC, try calculating the first few powers of any number (While looking at the last digit of the result), do you notice something ? answered 31 Dec '14, 18:02 1.4k●12 accept rate: 28%
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• 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:

×25

question asked: 31 Dec '14, 16:24

question was seen: 462 times

last updated: 31 Dec '14, 19:24