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

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

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…

1 Like

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.

1 Like

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 ?

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

1 Like

Thanks a ton…

thanks for pointing out… thanks a lot

Welcome if it helps please upvote and accept it as correct answer

i wish i could upvote but i have less reputation but i will certainly accept it as correct answer…

Thanks I didn`t notice that!!!

Happy Coding !!!