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.
10162 - Last Digit
Moderator: Board moderators
-
- New poster
- Posts: 23
- Joined: Fri Sep 01, 2006 10:17 am
- Location: CSE, SUST
Thanks
Thanks to Piklu_sust and pradeepr for the hint.
I got AC
I got AC

Re: 10162 - Last Digit
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.
Re: 10162 - Last Digit
100 & 0 both have the same result as well as 152 and 52stcheung 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.
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;)
Beliefs are not facts, believe what you need to believe;)
10162 help me
i don't no have any mathematical equation
s=1+2^2+3^3+4^4+.............+n^n
please help me
s=1+2^2+3^3+4^4+.............+n^n
please help me
Re: 10162 - Last Digit
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.
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.