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

×

Corner case in What is the last digit?

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

emin3m's gravatar image

2★emin3m
629
accept rate: 3%


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..

link

answered 31 Dec '14, 16:40

damn_me's gravatar image

3★damn_me
2.6k21336
accept rate: 24%

edited 31 Dec '14, 16:47

Thanks a ton.. :)

(31 Dec '14, 16:53) emin3m2★

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.

link

answered 31 Dec '14, 16:43

the65bit's gravatar image

4★the65bit
1.1k101328
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★

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!!

link

answered 31 Dec '14, 19:24

ansh1star033's gravatar image

3★ansh1star033
206129
accept rate: 9%

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 ?

link

answered 31 Dec '14, 18:02

hemanth_1's gravatar image

6★hemanth_1
1.4k12
accept rate: 28%

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:

×25

question asked: 31 Dec '14, 16:24

question was seen: 462 times

last updated: 31 Dec '14, 19:24