-
Notifications
You must be signed in to change notification settings - Fork 1
/
Problem013_LargeSum.cpp
30 lines (26 loc) · 2.04 KB
/
Problem013_LargeSum.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <iostream>
#define SIZE 100
#define TEN_DIGITS 10000000000
using std::cout;
int main()
{
int64_t values[SIZE] = { // first 15 digits of all numbers
371072875339021,463769376774900,743249861995247,919422133635741,230675882075393,892616706966236,281128798128499,442742289174325,474514457360013,703864861058430,
621764571418565,649063524627419,925758677183372,582035653253593,801811993848262,353986643728271,865155060062958,716938887077154,543700705768266,532826541087568,
361232725250002,458765761724109,174237069058518,811426604180868,519343254517283,624672216484350,157324443869081,550376875256787,183363848253301,803862875928784,
781828337579931,167263201004368,484030981290777,870869875513927,599594068957565,697939506796526,410526847082990,653786073615010,358290353174347,949537597651053,
889028025717332,252676802760780,362702185404977,240744869082311,914302881971032,344130655780161,230530811728164,114876969321549,637832994906362,677201869716985,
955482553002635,760853271322857,377742425354112,237019132757256,297988602722583,184957014548792,382982037830314,348295438291999,409579530664052,297461521855023,
416981162220729,624679571944012,231897067725479,861880882258753,113067397083047,829591747671403,976233310448183,428462801835170,551216035469812,322381957343293,
755061649651847,621778427521926,329241857071473,995186714302352,732674608005915,768418225246744,971426179103425,877836461827993,108488025216746,713296124747824,
621840735723997,666278919814880,606618262936828,857869440895529,660243964099053,649139826800329,167309393198727,948093772450487,786391670211874,153687137119366,
407899231155355,448899115014406,415031288803395,812348806732101,826165707739483,229188020587773,771585425020165,721078384350691,208496039801340,535035342264725
};
int64_t sum = 0;
for (int i=0; i<SIZE; i++) // sum all the values
sum += values[i];
while(sum >= TEN_DIGITS) // take out all digits more than 10
sum = sum / 10;
cout << sum;
return 0;
}