Zjut practice 3.3 K-K Problem B. last digit

Source: Internet
Author: User

Problem B. last digit

Background

Give you a integer number N (1 <= n <= 2*10100). Please compute

S = 11 + 22 + 33 +... + NN

Give the last digit of S to me.

Input

Input File consists of several NS, each n a line. It is ended with n = 0.

Output

For each n give a line containing only one digit, which is the last digit of S.

Sample Input

1

2

3

0

Sample output

1

5

2

 

# Include <iostream> # Include < String > Using   Namespace  STD;  Const   Int Maxn = 101  ;  Int  Sum [maxn];  Int Myfun (Int  N ){  Int Ans = 1  ;  Int Len = n % 100  ; N = N % 10  ;  For ( Int I = 1 ; I <= Len; I ++ ) Ans = (ANS * n) % 10 ;  Return  Ans ;}  Int  Main (){  For ( Int I = 1 ; I <= 100 ; I ++ ) Sum [I] = (Sum [I- 1 ] + Myfun (I) % 10  ;  String  S; While (CIN> S & S [ 0 ]! = '  0  '  ){  Int  N;  If (S. Length ()> = 2  ) N = S [S. Length ()- 1 ]- '  0  ' +10 * (S [S. Length ()- 2 ]- '  0  '  );  Else  N = S [S. Length ()- 1 ]- '  0  '  ; Cout <Sum [N] < "  \ N "  ;}} 

Simple simulation with a cycle of 100.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.