Ultraviolet A-10162 last digit

Source: Internet
Author: User

Description


Problem B. last digit 
Background

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

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 lastdigit of S.

 

 

Sample Input

1

2

3

0

 

 

Sample output

1

5

2

Question: How many digits is s?

Idea: If you see such a large number, first create a table and try to find that every 20 items is a small loop, and every 100 items is a large loop, and the result calculation of 100 items is recorded directly.

# Include <iostream> # include <cstring> # include <algorithm> # include <cstdio> using namespace STD; const int maxn = 300; int num [maxn]; char STR [maxn]; int main () {int ans = 0; For (INT I = 1; I <= 200; I ++) {int TMP = 1; for (Int J = 1; j <= I; j ++) TMP = TMP * I % 10; ans = (ANS + TMP) % 10; num [I] = ans;} while (scanf ("% s", STR )! = EOF & STR [0]! = '0') {int Len = strlen (STR); int CNT = 0; For (INT I = 0; I <Len; I ++) CNT = (CNT * 10 + STR [I]-'0') % 100; If (! CNT) CNT = 100; printf ("% d \ n", num [CNT]);} return 0 ;}



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.