Large sum
Work out the first ten digits of the sum of N 50 - digit numbers.
Input Format
First line contains N, next N lines contain a 50 digit number each.
Constraints
1<=N<=10^3
Output Format
Print only first 10 digit of the final sum
Sample Input
5
37107287533902102798797998220837590246510135740250
46376937677490009712648124896970078050417018260538
74324986199524741059474233309513058123726617309629
91942213363574161572522430563301811072406154908250
23067588207539346171171980310421047513778063246676
Sample Output
2728190129
Explanation
Summing the numbers we get 2728190129820036131461476701043585006837989465343, first 10 digits are 2728190129.
Solution in python:
n = int(input())
tot=0
for i in range(n):
a=int(input())
tot=int(tot)+a;
while (tot >= 10000000000):
tot = tot // 10
print(tot)
You can also run it on an online IDE :
Your feedback are always welcome! If you have any doubt you
can contact me or leave a comment!
Happy Coding!! Cheers!!!
No comments:
Post a Comment