10162 - Last Digit

All about problems in Volume 101. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

pradeepr
New poster
Posts: 21
Joined: Fri May 25, 2007 11:52 am
Location: India

the problem with ur code!!

Post by pradeepr »

the code only works for small numbers..

remember that the N can be as large as 2 * 10^100 which cannot be accomodated by int or large.

So u have to use strings. treat N as string and solve the problem.


considering the input size ,u have to scan N as a string.
Piklu_sust
New poster
Posts: 23
Joined: Fri Sep 01, 2006 10:17 am
Location: CSE, SUST

Post by Piklu_sust »

You needn't use string to find only the result. There is great symmetry. Just gets your hands dirty by some input and output. This is easy to find the symmetry (you will find same result after specific range that is very small). So, you needn't trace the number just look at the last two digits.
zyxw
New poster
Posts: 24
Joined: Sat Mar 22, 2008 5:49 am
Location: Chennai
Contact:

Thanks

Post by zyxw »

Thanks to Piklu_sust and pradeepr for the hint.
I got AC :wink:
stcheung
Experienced poster
Posts: 114
Joined: Mon Nov 18, 2002 6:48 am
Contact:

Re: 10162 - Last Digit

Post by stcheung »

This problem is meaningless from a programming point of view. It's merely testing how well you can do finger math, so let me spare you from doing the brainless math. The sum of digits is guaranteed to be 0 after N advances by 300. In other words, the result for N=456 will be the same as N=156. This will reduce the problem to a simple simulation, which then tests how well you can type numbers.
Angeh
Experienced poster
Posts: 108
Joined: Sat Aug 08, 2009 2:53 pm

Re: 10162 - Last Digit

Post by Angeh »

stcheung wrote:This problem is meaningless from a programming point of view. It's merely testing how well you can do finger math, so let me spare you from doing the brainless math. The sum of digits is guaranteed to be 0 after N advances by 300. In other words, the result for N=456 will be the same as N=156. This will reduce the problem to a simple simulation, which then tests how well you can type numbers.
100 & 0 both have the same result as well as 152 and 52
the result is the same for n and n+k*100
f(n) = f( n%100);

20 has the same result of 0 + 4
40 has the same result of 0+ 2*4
60 has the same result of 0+ 3*4
f(n) = f( n%20 )+ n%100/20*4

you can also go more further for cycles of 10
>>>>>>>>> A2
Beliefs are not facts, believe what you need to believe;)
@mjad
New poster
Posts: 44
Joined: Thu Jul 22, 2010 9:42 am

10162 help me

Post by @mjad »

i don't no have any mathematical equation
s=1+2^2+3^3+4^4+.............+n^n
please help me
torryton
New poster
Posts: 3
Joined: Thu Nov 10, 2011 12:45 pm

Re: 10162 - Last Digit

Post by torryton »

There are a few simple observations right away. 1^1, 1^11, 1^21, etc. will all end in 1. Similarly, all powers of 5 and 6 end in 5 or 6. What about the other numbers? It turns out that if you look at i^i, i^(10+i), i^(20+i), etc. you can find a cycle for the last digit of each 0 <= i <= 9. The cycles are as follows:

0 - 0, 0, 0...
1 - 1, 1, 1...
2 - 4, 6, 4...
3 - 7, 3, 7...
4 - 6, 6, 6...
5 - 5, 5, 5...
6 - 6, 6, 6...
7 - 3, 7, 3...
8 - 6, 4, 6...
9 - 9, 9, 9...

All these cycles are of length at most 2, so for every 10*2 = 20 elements in your sequence, the last digit must increase by a certain amount.
Post Reply

Return to “Volume 101 (10100-10199)”