NTOU CSE C++ Programming
教學文件和作業說明文件: https://hackmd.io/@kogiokka/ntou-cse-cpp-nav
這次主題是大整數(Big Integer)。程式語言中的整數型別通常佔 4 或 8 個 bytes,能儲存的數值大小有上限。因此如果想表示一個很大的整數,就不能依賴程式語言預設的基本型別。本次實習讓學生學習利用動態陣列表示任意大的正整數,並實作加法運算。
練習 class 基本語法:
完成範例程式的BigInt
類別:
Add
的實作(加法運算)提示一:動態陣列中整數應該倒著存。陣列的第一個元素存個位數,第二個存十位數,依此類推。
提示二:加法運算的邏輯只需要寫
BigInt
對BigInt
就好。其他的多載函式請善用相應的建構子。
test-data.txt
、test-data2.txt
存成檔案後跟可執行檔放在相同的資料夾。install/
資料夾,不用額外做設定。其他環境下可能要設定安裝路徑的變數: CMAKE_INSTALL_PREFIX
,詳情請見CMake專案建置的「CMake安裝指令的相關設定」一節。。BigInt
├── BigInt.cpp
├── BigInt.hpp
├── CMakeLists.txt
├── main.cpp
├── test-data.txt
└── test-data2.txt
不是使用 Visual Studio 嗎?請見 CMake專案建置。
將 BigInt.zip
解壓縮之後,在 Visual Studio 選擇開啟本機資料夾或檔案 → 開啟 → 資料夾,並選擇剛才解壓縮的資料夾。Visual Studio 會自動開始設定 CMake 專案,可能會花一點時間。等到專案設定完成後,方案總管會跳出專案資料夾的內容。
這時在上方工具列的執行安鈕選單選 bigint.exe (安裝)
就可以自動編譯執行了:
CMakeLists.txt
cmake_minimum_required(VERSION 3.12)
project("Big Integer")
add_executable(bigint)
target_sources(bigint
PRIVATE
"main.cpp"
"BigInt.cpp"
)
# 設定安裝路徑。
# set(CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/install")
install(TARGETS bigint DESTINATION "./")
install(FILES
"${CMAKE_SOURCE_DIR}/test-data.txt"
"${CMAKE_SOURCE_DIR}/test-data2.txt"
DESTINATION "./"
)
BigInt.hpp
#ifndef BIGINT_H
#define BIGINT_H
/**
* @class BigInt
*
* Arbitrary-precision integers. BigInt provides addition operations.
*/
class BigInt
{
public:
/**
Default constructor. Create a BigInt with default value 0 and default capacity 100.
*/
BigInt();
/**
Destructor. Destroy the instance and release the memory.
*/
~BigInt();
/**
Constructor. Create a BigInt with an integer.
*/
explicit BigInt(const int value, const int size = 100);
/**
Constructor. Create a BigInt with a string.
*/
explicit BigInt(const char* const value, const int size = 100);
/**
Copy Constructor. Create a BigInt with another BigInt.
*/
BigInt(const BigInt& value);
/**
Addition operation. Add another BigInt.
*/
void Add(const BigInt& value);
/**
Addition operation. Add a value from an integer.
*/
void Add(const int value);
/**
Addition operation. Add a value from a string.
*/
void Add(const char* const value);
/**
Write the integer to the standard output.
*/
void PrintValue();
private:
/**
Reset the integer to zero.
*/
void setZero();
/// An dynamic array storing the digits.
int* m_digits;
/// Size of the dynamic array.
int m_capacity;
/// Number of digits in the integer
int m_numDigits;
/// TODO: sign of the integer
};
#endif
BigInt.cpp
#include "BigInt.hpp"
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <sstream>
using std::cout;
using std::endl;
using std::malloc;
using std::ostringstream;
using std::realloc;
BigInt::BigInt()
{
m_capacity = 100;
m_digits = static_cast<int*>(malloc(m_capacity * sizeof(int)));
setZero();
}
BigInt::~BigInt()
{
assert(m_digits != nullptr);
free(m_digits);
}
/// BUG
BigInt::BigInt(const char* const value, const int size)
// Member initialization list.
// Set initial values of the member variables.
: m_digits(nullptr)
, m_capacity(size)
, m_numDigits(0)
{
int numDigits = strlen(value);
if (numDigits > size)
return;
m_digits = static_cast<int*>(malloc(m_capacity * sizeof(int)));
m_numDigits = numDigits;
setZero();
for (int i = 0; i < m_numDigits; i++) {
if (value[i] < '0' || value[i] > '9') {
break;
}
m_digits[i] = value[m_numDigits - i - 1] - 48;
}
}
BigInt::BigInt(const int value, const int size)
: m_digits(nullptr)
, m_capacity(size)
, m_numDigits(0)
{
// TODO
}
BigInt::BigInt(const BigInt& other)
: m_digits(nullptr)
, m_capacity(other.m_capacity)
, m_numDigits(other.m_numDigits)
{
// TODO
}
void BigInt::PrintValue() const
{
ostringstream oss;
if (m_numDigits == 0) {
oss << '0';
} else {
for (int i = m_numDigits - 1; i >= 0; i--) {
oss << m_digits[i];
}
}
cout << oss.str() << endl;
}
void BigInt::setZero()
{
for (int i = 0; i < m_capacity; i++) {
m_digits[i] = 0;
}
m_numDigits = 0;
}
void BigInt::Add(const BigInt& value)
{
// TODO
}
void BigInt::Add(const int value)
{
// TODO
}
void BigInt::Add(const char* const value)
{
// TODO
}
main.cpp
#include "BigInt.hpp"
#include <cstring>
#include <fstream>
#include <iostream>
#include <string>
using std::cerr;
using std::cout;
using std::endl;
void testBigInt();
void testBigInt2(BigInt sum, const std::string& filename);
void cut();
int main()
{
cout << R"(
____ _ ___ _
| __ )(_) __ _|_ _|_ __ | |_
| _ \| |/ _` || || '_ \| __|
| |_) | | (_| || || | | | |_
|____/|_|\__, |___|_| |_|\__|
|___/
)";
cout << "CMake project setup successfully!" << endl;
cout << "Uncomment the test cases to proceed.\n" << endl;
/**
// Test cases
cut();
testBigInt();
cut();
// An 100-digits integer
BigInt sum("7656139888" // 10
"7587476933" // 20
"8781322035" // 30
"7796268292" // 40
"3345265339" // 50
"4495974574" // 60
"9617390924" // 70
"9090130218" // 80
"2994384699" // 90
"0440010000" // 100
);
sum.Add(2048);
sum.PrintValue();
// Ans: 7656139888758747693387813220357796268292334526533944959745749617390924909013021829943846990440012048
sum.Add(sum);
sum.PrintValue();
// Ans: 15312279777517495386775626440715592536584669053067889919491499234781849818026043659887693980880024096
cut();
testBigInt2(BigInt(), "test-data.txt");
cut();
testBigInt2(BigInt(), "test-data2.txt");
*/
return 0;
}
void testBigInt()
{
BigInt x;
BigInt y("1234");
BigInt z("000009876054321");
x.PrintValue(); // 0
y.PrintValue(); // 1234
z.PrintValue(); // 9876054321
y.Add(z);
y.PrintValue(); // 9876055555
BigInt i("444", 2);
i.PrintValue(); // 444
BigInt j(i);
j.PrintValue(); // 444
j.Add(4000);
j.PrintValue(); // 4444
i.Add(78);
i.PrintValue(); // 522
i.Add("98765");
i.PrintValue(); // 99287
i.Add(j);
i.PrintValue(); // 103731
}
void testBigInt2(BigInt sum, const std::string& filename)
{
std::ifstream file;
file.open(filename);
if (file.fail()) {
cerr << "Cannot read the file: test-data.txt" << endl;
return;
}
std::string num;
while (file >> num) {
sum.Add(num.c_str());
sum.PrintValue();
}
file.close();
sum.Add(sum);
sum.PrintValue();
sum.Add(sum);
sum.PrintValue();
}
void cut()
{
static const char* DIVIDER = "\n"
"===================="
"===================="
"===================="
"===================="
"\n";
cout << DIVIDER << endl;
}
test-data.txt
13728555404939069403172089703708212698089662993562047731042344497291384320132824
86906110661226573029000112203505963809956213968756170301614952324207931999212942
64998143457798538265423603996872591290077341532308005789752533980866844262751233
06654357035559680264575064985072498546131528081110079138943503660808461244574287
90444798684694830794095764476844255175770545732962141612251200079197370769214871
06138471138087576779296203489001696143331800246517739362033926836846899197084833
59548245460759111245733133257841547659319915391428728309529823981230986727344188
17711410062604484842466382091670522367975368445731228046650727977986249353323286
03012064496000181160617140174137636635093663712584552289967534190781339549802577
54467471629136805865037445439982858848287247068021791273618113596353408982624102
21600756468870750168414303941668723665909039592571708213552642441360532939743292
37643383737152277263148085730620643942837729639915369836595928059969491703335987
70769435215234662342635047341815627162211462212028380587026594158868071174779798
17367425868951817117143661330993308066375925018816624158993203940393840072024369
06924848307671700530997687721139783065332053395389809804201804926095538766286585
72709006918000761917847767509618776573659824332929354426055291687130275137413838
29650823188418215760541044221414935030472216452263141948524117953590772483807891
22710278596685792726213752149424252608577328910124863548253862980578145499547320
82180369043025204590059693616452566589111119934049738176737138832293290803183081
84449407918263634199917198974195567162025855055993811253435572849072265745269131
53608680747796361479642604012261750497098854777712037124754759343918206195317176
86038377209754611990727062761419125856277836548716698992906615945534601438226926
85924636586780709118755509159227731475423776218350088643508292974436033760532264
98282109846713119277010618533329977084538167490303748604376384888616344248866945
17440247888208067620422699584365679356599749310713411772169703511998594706534801
90183687281880453590018632810989376759238674119409734322138923037231238676925447
90982182743229292672426806307622953580296670215053081277799456068830407286198971
43860548264528391399625507624189104877281569421490160754761959279226030660882335
77416985013659258676555112544595036903395158235102493137371603111859008376914240
03283304306244572587461038363294434524123993337858334352584394118687580850510441
test-data2.txt
13728555404939069403172089703708212698089662
8690611066122657302900011220350596380995621396875617030161495232420793199921294264998143457798538265423603996872591290077341532308005789752533980866844262751233
066543570355596802645750649850724985461315280811100791389435036608084612445742879044479868469483079409576447684425517577054573296214161225120007919737076921487106138471138087576779296203489001696143331800246517739362033926836846899197084833
595482454607591112457331332578415476593199153914287283095298239812309867273441881771141006260448484246638209167052236797536844573122804665072797798624935332328603012064496000181160617140174137636635093663712584552289967534190781339549802577544674716291368058650374454399828588482872470680217912736181135963534089826241022160075646887075016841430394166872366590903959257170821355264244136053293974329237643383737152277263148085730620643942837729639915369836595928059969491703335987
707694352152346623426350473418156271622114622120283805870265941588680711747797981736742586895181711714366133099330806637592501881662415899320394039384007202436906924848307671700530997687721139783065332053395389809804201804926095538766286585727090069180007619178477675096187765736598243329293544260552916871302751374138382965082318841821576054104422141493503047221645226314194852411795359077248380789122710278596685792726213752149424252608577328910124863548253862980578145499547320821803690430252045900596936164525665891111199340497381767371388322932908031830818444940791826363419991719897419556716202585505599381125343557284907226574526913153608680747796361479642604012261750497098854777712037124754759343918206195317176860383772097546119907270627614191258562778365487166989929066159455346014382269268592463658678070911875550915922773147542377621835008864350829297443603376053226498282109846713119277010618533329977084538167490303748604376384888616344248866945
174402478882080676204226995843656793565997493107134117721697035119985947065348019018368728188045359001863281098937675923867411940973432213892303723123867692544790982182743229292672426806307622953580296670215053081277799456068830407286198971438605482645283913996255076241891048772815694214901607547619592792260306608823357741698501365925867655511254459503690339515823510249313737160311185900837691424003283304306244572587461038363294434524123993337858334352584394118687580850510441953635891240812873666470033695104119889267869677634061511557380098915586345096822645053145173550941087467481514711798363097420837989395630934338962528182315608640581402538560155439598867610579365247884542164647344628284200113457185815074968245879420196275106753069293835983333710224828513725690602133393757088366185508888031952934429949766187845918403953238084913927577772347677845927320518834115735190310775753988833054360069094982357827780904115565201482436718887665409956070928
30825819763463662666977317892068479430560252761239935504220878682355627575378638711994515635491049883962307115281010981134781141073201571392694133914738690955793622672521738424733626367388950818328377999291535581644265365904340931652340093136362102052589015886907480948200438670146777260388298047634484400005415029373337378874698086825295294880983707268186844001194606784963436364769305501667400895167293190662639174425996803696582566864398929575289398865060763415983994071489452828599479235952586500597039893111814006550776880629304999846323452002278259055383406920140379714002435892352636537074066241340383687517276809662676127619793301612981356869128150793008274116337916837667107453390105138563237856846476288932154161838819550725612105978250328357301341515743363015565480859774082521389912817799939115261645253856979848230201560218295071335734785907708414950800575653965440953576907195806470315041416501709661404817418545405174620242407293171492210669819166888569380878830629296529125021352771984028204474522767069737072453682488910835626727381419534428258875267240248846052907269311059133053636078624750065426466235927206257368995220785019753880495928837923638752085614122494498203226413078586922633141918409427441120153263306138101696168610029834758063427168611049771498466
972758587673960522201322792303268617855832659914433389273019677291666028838028547271687248591403651472106766484984424591044611115500362253031005859974456527668144803436542894295024027821007574027914238556736481038213918038173698440506525558459697084122117757792543792804913648997712778609413721473358124632814797956850954984666973065819152693366604526547031690168380940176698765291421502701196549294061020404432814183147378252964165034170487436448519553753639842645690866040591098286343184871155725554920100922581811086844756426713493981025756980735409073853992860165376817219316381513492500596552452386413590757071603209022792585383751578735202225962738985693440318808823022024946904121567287000956459718919970060284531155472628205646103964343852761066298664718836212416959411155603286282041122893218881197616730527782665313951000591523344281012242043613511250089306332768175828402930270343537615273105518773774878385713189816699208589825274666780096874593765617618948075303470113004956599550325964977932247051153769570288741314370570926939241421507278329626221121420748646555664082794959828192200695778132363519488069349216651055545828167621295207935227237698541401654807673343053144612697331076153863548506257263433344271058786738256959862507121120810511152664794275442222684169487653448788633604951060572733806875690775679657862612058260181667181400834924338925588801797202128244147599891125845346219914991029092475020906778757867169118428974493112994318601556703482354262348300758563833312511705732346031267615575454373162283289947775857372211741114895745389616849168497350894622455069093026107447433826231259069051673000312852288894250699042522453950440293216386317284171423
96820182265437693328617477139610438071226958467274959093338543585230402268855515412602442473711196638933060635843240085299602174948791360392397664638638677376161180303942783198231572391497516239813871305677333599532089488675030313691208348403395426807736507188691344254127000070872243257907974740477135234963316514744400024338405603683690410822974924051697809272811270720943793265127210557724777519939633927142472413827319464804779673966646480334988185024168082914815404905756922330630387012860116884446178687502763276623791770376343959406327519651164660887136113939571893214948389887271414850561469294645646594981156442351074643020200492038221727704157526052051004289641775361675408584623503695457083119574879245274310640875614591105579478266864639058582930296147762265921007103646250759489015760311003092778500252018498584082446790751413430821483194041869090182891340327318029188191698037876214510655015127036277239742969855206337076976973686786715751717031094662192375353731446957866915416137003542149772620954517095187466074431617268161115167982073613205308336883127579999929339532895312981852338759840128557385877812183786563264196025800793937664700883746498529223795822846787970445406712363040925527815134556894967839222903642437482547196915414531519249016233377315853162422117984180718212874359430031890456515105249810336150638691612785099439595747462405625853873936169433918518778273148877507135340229913231424174055886442788875494711268201838964783419261984953252936328356834885132534866883514319493546036759238106103142070918646686938606099709966047808776939213236140182294559235139436683647095871482124759347946355403594335255067948137057564911193494025650062141211852725920523335687292333632648684877734023975369671387703224616268723022647160642780491743339240597333126613875018451409582864604571922090942193593616625131189585514185752920710094630275497234216713918654955854595906269590831802895797633526525696974481704936706520965268470980984131828642633364823774961119016112436724151193324388034666452615224157202793502696446059685765529133128556169992107776574207455886523842638725655913582684744648677062341359301194677779563838341912133148475823097492962215036184321026765528790815492792090993241836452704415497712206051913318371200531880142829815292257485921444131020218692206466953213431948854033229649113205363620615965088795634019720810124651346649543179600006273371991432581483863421839419444803353467059683950087860150107510285660960631940290884068979020124
2604300591144055128884695000667638770982927366047806950289222482282230404815644360399049437368795477905308093207023028447080104519927157280483187171137938947905118411828517209155151819322558516137275369409627480935130623806455551415222020375913692266338656571979926991980192300900657921078944772317345251819876782961017923317059369761797108891485171202853136833490322290041481835044754469511830751582355772238421788919567624634530616175834722757225559587717511841540432197138797779552510968568150134211079228433284157935576545492298044479958849140825000573384038425467182389594530122146441686127657136072863743227690178166082557979998816054229747695365353760080512536463403170530804403573463425234545394705637172982410791227223461904946211877131582471014034565230986396142110935075720565415904999442671640888955919153981102283868844534452748691372764155461908003506864916923926324765557166271339382604378198493983991030592895013708294193641908902520589867807163088012510084994512980779522113101569214625246370865843109981891777857228993991769375859875504646105277006838284188053770488465440218873675577647746438900161146219406420075909268362647490618518999505099954518232223027974084594394293833946884796503779036891294094354784553679226040739653956813222410502133238813426043532658702585068817524686327077310876355841693781978085829665086350054975525521427027959345192651374186713687856397253520085227031509953883762278167534800993133089561894075090076489306387684625848958139673597811121906211112250686331962793706689109734761200461091199750766492196421753275741700464306926600215347966014905520386727467651409835749378214893728457413703172248611498665690179266719235967793909643810752580492050308257230151699485679242578185771837173169059257073542038748651935945809037101281814841071670828624404347477274948207712102821757943037136930388383163849766066750901351634888227032553152012435036717298361557354813158079706749237387206042898624680192326011309503530611413736410097374828771456614020346775302528666397455887155992820695136281950259828871321816962156386891823065280955748277335389134464650680800931499653099161659653205010380899464523582631816549321096428682517310767876296928794476023934847807685801818100290602519620329350670377631878482169105530733129278401335909662300428708254995534468528959450842537592543134574995461059935041378037401436042550723038157345780497044600882732767639060044189431757537984235608012988172503609254033652187666454838366541973985498142383820717178427174641167223267553998867753586576168002531661496029471690562345074363976325223598919666746271117179599556321704329273278635843229860914444997182002700601486101758508719494483288144284311828889735755833678781200004706193416195876943177997912887471365295127590154204350025473425052406508501344468738497317345189547084776796016789009494709548674809837557721543596500956168544889105075153131415516519272196031319204778510495690234627898195381631921507592001067191202735252431202934963641160767690310287643790202525195218334339344415716865255676993034670094074759949112812828601871008073319138221273840176480186032239570032631530706128748350688757508996831684310538149538425097630294676107199181720610724469317578214428098355032636535807223062679854496858165394667911384245180598195533762912932
352573074679260430625198577679898296964796304696413485126467056877478440172280397623797042872262482273177709791658101210098354149774618719363654652885617821824294237585672303647577070682717041923919410013393159512662479013851693455049047992998747695246143936692514868068990600160403140442550827687528651250110609509979637408570072770577751225780668330053371305488755592212855184609284141815000015785455276117698818230840393732419895176256615947306888888714768489796297235658332218448917785408964552682317190080468791052087163312300701886622799161516631636287074958803926851963105460301839130653124955085945652151135079209745422425086778512673963354694406428445254076652636532184925121485345332415527564523515997598216901949079279447804907757695548108926023747967008804361001997081061017304973864156772859803186218601473922474180776191184033746488666388134518537092181129691335519421446357690884078300800711083783305946119289622352260607100129586452070994397166592823625532779434512811413724970192501434760671975506308869583402831566409339763316717189898350334823387902903169828070356903584449224701273621755091530034805190336104750265221199115485948078624774142028066762085214607061422513287148208704635178351222261446756130758793051931046164825921138003830013217874895039673450944331943996236850658839178196279456049607067436797165182127746688013531714263465720284677919115885007165208210394863468977314156495032508539710212557641681241661766273627903495679377495639402215030892994653630549014410924126346759539926274075890755571684665373816600461399849878735060621411728512447564499132494381689283445682573498306417443339740723935199294749914927386018898071522379209708587646480204216926364695924289467568231791000823838021688466387612920330728462786784555194944222247891035651857527240581611046654750518711516131028143233484122804948567073017316116969949819364607295571861133649114943935283194002638253690542306723897137477953931613707779460042285415692633446148066734234136670952262720236943974642976022276040891321210490572634595228388857584801441840877675347760432279853869165037691363501016045273902335377219932737758743883865385901670214978224376629259190983162086459407771265123156525120438995065800159293698480991249936098194072292462048219003203478808214381818594491837576216178220049166574362648211337122986594066427366254606395691056770228890574448035572445698760080560327067041229516267240355907818786981267874221902663934969704923337528135033461593718916935503133559673133681372711000862698140377774856987945284220488327281549347789421695867758041138712099766723767334182544453538152921014376499452869318268141090750699761419515446476710347198326276267332097563759127695137014743062142941662138100343017857866871893375222187154391668520467518153908592475559619623581250575840231595652244134261963212546850526846553172877581166600835309139660943534535282645505333369700047836849410967168808440789880312672472808299725333150429578513732437605448882953437031315900781627831081074175329133464413496487977861136256307914600295677113916933092811580240701654775991002689480456240065806249798005439153157322256510945250738653606116997159551156424061254009582635597062055774562551644391778636966841884818634190804961320414323849831847890159857817312744439500053254450240507394305042678177433125060928699449535945154987268708383886979914204024751077977768411867434657086494483056870249868899849093017995385325553271365723923226117666064049551955346022572827139373996736646759311332381922285078598445399017370506883433480497855565909771735937541168017974537922880597884857063865293656761248008797797819145431235924785334740105776862211805554374017813429022906613106863019473623925469201952000217663205884238058857979571167979678146397883049888049124764266973664451376726366177499933716368485496623375245546317564934759232318415074497629534031326597119574027394579161148972377174450234226526398799440019392950020320508035018267519416494137668137282446361238071866636739335605590388192732128799391766223063005326199955943698177337035019068936428822163023281141489408110436569603
79143941161222421134756510806369618196898641307656539750507118827545047459515109210715868533837523611150198941843124754186612064698664217350491258211709645320904156082682998926610753692454850091930028186910813990521549987462886956194845650462556142740766553116379076602315711913097804925134836128522238204097864341293419786795600197365842366428299205484200632149941174194553255510236054511274010449397787016263027511440569272238208709755252219168114462447975209320218943813803237327139072548580363660284945223764475866359149048310899618825765894038088033861949307201508067194195995830707077034709551454006327676906095923024803103993837318465921238423322731190630549457355487273759948264612407457354238940059660565132914824602324280090453612839367053029113591677980243496070206316930940027944588797833458221337456368319255310474731271680884440908124476485397810160589879528838488316912663393880850498117162579908466485404548906438331550651002038771812406647691229705939199319683307029586852385659441625915601467850362809051655930305190081154955889477050991709252010278602309959990227449539273272901619925553717876132754887754387219935182508696367305997811543941349241766041010232883392673802665930652753405159059099408491412237540390297569006452271239290391451277502740667044809595258980116753415887287842505086780334333435471914923758519398446257823631256110533013248203775885635412752340593930452583596995015420291673936424989012563755827023043221375042118549718549984947607812659233881678429757246126609207186278730958867913747716775135802803836595195297282432216511280074138752659236316906072723921944338278633007482182658140981546986090888736585302680015359723930009141384140561317046100150339483463032723276147741611911734989987903294537422918835755563804970167803641170089726085679527785222642880883023299892139423214318151123690473742203752578063176708217327008883709190835488863549585642770336602619682905004440545064197862545051349751318655996965725261224333846388819454106719401676236669081647741552878868548719258511181042814827749931951835255406007987547292866704858102540810403246941733323370639096793609165872490902162412101889536088336641491951448392344317373040119110924305881744674112094459581658330196213275530014922895264547808396179621179734667909582540693559799296557822093571097741198444061438720904744606621010423717113553232213342970600904887267837948367884756033252073911561214665605739960248533267394494912222265864996422221288251680441528689776772799720017532922227224394341860683084102375691901467322619611756139892046525717195202074232768009466135889119526409065130594064772293272156036814033201709601791636144765177171719976994648729595302653702644945158475661276231688425033335401874938442616734599328238116171532048281424352267495357366014496551264015812592634751933559431156148410661141019308498096759770105831139470464589229944291696224526005028954268033586212549830591154562240695395696736790995594443204838096244500413355046457966218327417119181486219241742823423596465885134577304440328373610614736773131567943073607858103852501916688098275173410726509366936786532093658796106805179947967625969242305982301124195009184108115992663272202521084146284937730777034161073848876990600120815190505372714375954471164620431658050432964543851780074817975493125092612934333105267659816181839198116947057740865253216650805841369148262647006986340211412762141596619073371032863454779434512499158255561297285278958957097216790151744362570659551970431888966410909024694677264454906967729693415185376276649529401806208028202428641376414139630428166928627272595973868221763777710226672450721823109252054882658952482531638916508613002712996977799344991225517506915544602100961276965772646448635904948442876223410800048367987622702688516539137135735522669029890797155108081829258275376200870647094801966853182604164738496038353859321333494267995999581463359688869831846776525202266712396275211339925018318541199864390502632405520411483314113006907696534156161669764254984103191957229256266289562605439922272446752207046443938818936299242278815886254632029798248194916764237654547256904169503783907270002723329779077690276994669210887118969948472933716651885374101789332457985419714268003178993390111395325672643736201068799758353575018862902367383117212795467400646111794795485663004797909756337383883832569765844486415560160355369051936585585225547934366698848738008087889012291242385976022976879883239191602056169832935324731437014225030583972361383636287786732708475789988398463858020865522601186418031290362715431055105970569235580923269340640882067507246981777681178653508796252912363294715057450093440044637252780409037129789588480820158126421126166433119739250014291066067103521911015939517433406051239339099135060372722188037522416248405450214619796684904559306514955448345832939973372014523959681689899949727927109970915438109261700755215774242373329193
9758800147230441364940067737629724267789495133437902185231440687109846850636144380099873463638315148991728298122033356354517921412768790740865868179278375935463048392519469202622915045481412671241987421006155396670134490999379703029675174589548207343841650869981851325196241444047250234125599598103239998585995003435281999839335940176071824247962961389497089327327497725429986186668543467719894908942685390446320023030644494888792734335849898918538685688454053767908976296753379165477119577825897131267426873248687497237940676210239068913731360228293327991344595664031846087759630256180839538046141510616706501435759274395074492737239546589191011825265221297230213113407905053245114975469507761237741252716023016260470388796964738289766026815163511275341310759465498403521699526552578327779978364339753539103925983007523130715981679444793621551254003594155990933627113710433187766855824763032328481821609981522995323775601660067979868543689950910771558188575614824884320291531130081713368878305671164144401501463917016330789088258627099319442346798040487546394222682945196169897678122308633516632481520048588413327114725257392611695319822521306898933431486130989380123132973200546145112501613860763961164027683677531746553281932494603192766043235184136987575004285157957347291407516598407343689788849000027681777020146941562819090521465853903811854912473780187569427059303569691239688356876285385441829200408668811291668355338422046120038530592736997263995352853510406606178161900271430260486275632363871121268209766506119107255034692395134860458356447308796298178429491189227348046782557199599017044379850398797772851403913604274404497600217231859689714328395216734651991029781551604386010268702873326592129516195314220175916235957656602799810046111918221402917414745282368997820806703127186276844630726953976875255195161257257319075658041632158018320237875357083613484244191625593969169991835475190404868792899856789744141735485933808780846282645970899043252195408318793407192346753305056858554955035617428147667291257376420490519985598470173245981700306819886605016154082799591718396811182795122049628127663693089678897058484344120014892180657724783423659283762005875893149289361758009442830801040526222802511211703797619917685260679066321810085589806342809419155630881493670905285273651051488871987838229475896525438272548797497325004317021206592508045130681843779873387648115145396794764253730384551192041490805543299434622566082819566840956059240359259422092818118468044672539431184682480797212751106343460228463154410535038609353005309678931023573616994307744692217360536990389550210200701573435931027347540196454936213769810671148404412223615520572218632290150503550262229923431327523223498309232393950533312573653055561534548638038709977398263046494823368718427645911415309575147408538155313289948864073891168785372366246092033364034382315123403014429556640696152658266639656713879763745246236626197433574954931221664721642059153213555257242955494082875660126139342676282117050032963208244872583652759654362232370969843838514694072344632981115705549975150035237442908165415953482238145709700068185291291182624067932812368836946585654697762476085419913877421015553394701943436023942626681029830621819635802035968408397132033204987326066462496270492442193129937764903947748057236079984942090085811796697515893497031233222424458214963467923817773833796092246403229376684841064812407392195643106855528153898552578975647515264391141590757002838217549771333080572479291608081471086839684393363959781303227800973418805165970224164863109262673380693123283652026359949310172842494916167727629907577603914788870895808086378487135848939465815992446666759955499287613176082495025655263545623049651708088465608807672415250914737391415915216568698609485866802599333253611388591072988853138639459124854036220702389513345272535852863644301319909716026107389789093813857049483073788037655190613779846391640006506684015130253187293455366423095892868921352183739412245018467245735291405219672798987951434998641655820424585667485828068464368255290550997313664923870637239703800729413742373776129343309561964997805248593325491309284487327187495939969046389275496307853321846727098472298990310911214938280922180252770281461833793056580065002023780671947942641419884325728802563687869358930014220871634917739603555710148983428863438167411817393567906102039229089663382604230426472249503840875940477760383483433772228298889410130137267926757005707598315868485052225843223369843968905660212548984746297595406125511988967447010051189813275351343889432865148251815483959062920150929451022129734494967438666905957638421663656948438230354319416028476482048144126344802322906884296733697132614276938798391848542068166859847798524831859116492171441919187980218322822257273742209292239746731744988000264422498309120936906391441603359375304540069734162268162925233132656672595523084930252863420160448634252247599695450345769583974243550592422809715500858375066492685563281227198972321717827736013279283363803246564461020118956778355080222185342251993586975868305564825140996333627125081895710898511961124349723701631075283264681461930323159031540154639479318811922654211937374493213348179009965346095844148767130950414052262238815591217769189301815563857210754615156374402454183333664425388069338837105351435288734523947127030091239221521007804455506865379592052149682784289139311857692109034185195885297365347820735539654310251019577263213568843100235162765279827417017464613118177790427177620809576312555845578072634346774617436195897860393302784647219295622359696175954511768156452271039521674595348396891223248672125813871988501766986020618939585319131474082498224900078775038788200231593128330755225
97588001472304413649400677376297242677894951334379021852314406871098468506361443800998734636383151489917282981220333563545179214127687907408658681792783759354630483925194692026229150454814126712419874210061553966701344909993797030296751745895482073438416508699818513251962414440472502341255995981032399985859950034352819998393359401760718242479629613894970893273274977254299861866685434677198949089426853904463200230306444948887927343358498989185386856884540537679089762967533791654771195778258971312674268732486874972379406762102390689137313602282933279913445956640318460877596302561808395380461415106167065014357592743950744927372395465891910118252652212972302131134079050532451149754695077612377412527160230162604703887969647382897660268151635112753413107594654984035216995265525783277799783643397535391039259830075231307159816794447936215512540035941559909336271137104331877668558247630323284818216099815229953237756016600679798685436899509107715581885756148248843202915311300817133688783056711641444015014639170163307890882586270993194423467980404875463942226829451961698976781223086335166324815200485884133271147252573926116953198225213068989334314861309893801231329732005461451125016138607639611640276836775317465532819324946031927660432351841369875750042851579573472914075165984073436897888490000276817770201469415628190905214658539038118549124737801875694270593035696912396883568762853854418292004086688112916683553384220461200385305927369972639953528535104066061781619002714302604862756323638711212682097665061191072550346923951348604583564473087962981784294911892273480467825571995990170443798503987977728514039136042744044976002172318596897143283952167346519910297815516043860102687028733265921295161953142201759162359576566027998100461119182214029174147452823689978208067031271862768446307269539768752551951612572573190756580416321580183202378753570836134842441916255939691699918354751904048687928998567897441417354859338087808462826459708990432521954083187934071923467533050568585549550356174281476672912573764204905199855984701732459817003068198866050161540827995917183968111827951220496281276636930896788970584843441200148921806577247834236592837620058758931492893617580094428308010405262228025112117037976199176852606790663218100855898063428094191556308814936709052852736510514888719878382294758965254382725487974973250043170212065925080451306818437798733876481151453967947642537303845511920414908055432994346225660828195668409560592403592594220928181184680446725394311846824807972127511063434602284631544105350386093530053096789310235736169943077446922173605369903895502102007015734359310273475401964549362137698106711484044122236155205722186322901505035502622299234313275232234983092323939505333125736530555615345486380387099773982630464948233687184276459114153095751474085381553132899488640738911687853723662460920333640343823151234030144295566406961526582666396567138797637452462366261974335749549312216647216420591532135552572429554940828756601261393426762821170500329632082448725836527596543622323709698438385146940723446329811157055499751500352374429081654159534822381457097000681852912911826240679328123688369465856546977624760854199138774210155533947019434360239426266810298306218196358020359684083971320332049873260664624962704924421931299377649039477480572360799849420900858117966975158934970312332224244582149634679238177738337960922464032293766848410648124073921956431068555281538985525789756475152643911415907570028382175497713330805724792916080814710868396843933639597813032278009734188051659702241648631092626733806931232836520263599493101728424949161677276299075776039147888708958080863784871358489394658159924466667599554992876131760824950256552635456230496517080884656088076724152509147373914159152165686986094858668025993332536113885910729888531386394591248540362207023895133452725358528636443013199097160261073897890938138570494830737880376551906137798463916400065066840151302531872934553664230958928689213521837394122450184672457352914052196727989879514349986416558204245856674858280684643682552905509973136649238706372397038007294137423737761293433095619649978052485933254913092844873271874959399690463892754963078533218467270984722989903109112149382809221802527702814618337930565800650020237806719479426414198843257288025636878693589300142208716349177396035557101489834288634381674118173935679061020392290896633826042304264722495038408759404777603834834337722282988894101301372679267570057075983158684850522258432233698439689056602125489847462975954061255119889674470100511898132753513438894328651482518154839590629201509294510221297344949674386669059576384216636569484382303543194160284764820481441263448023229068842967336971326142769387983918485420681668598477985248318591164921714419191879802183228222572737422092922397467317449880002644224983091209369063914416033593753045400697341622681629252331326566725955230849302528634201604486342522475996954503457695839742435505924228097155008583750664926855632812271989723217178277360132792833638032465644610201189567783550802221853422519935869758683055648251409963336271250818957108985119611243497237016310752832646814619303231590315401546394793188119226542119373744932133481790099653460958441487671309504140522622388155912177691893018155638572107546151563744024541833336644253880693388371053514352887345239471270300912392215210078044555068653795920521496827842891393118576921090341851958852973653478207355396543102510195772632135688431002351627652798274170174646131181777904271776208095763125558455780726343467746174361958978603933027846472192956223596961759545117681564522710395216745953483968912232486721258138719885017669860206189395853191314740824982249000787750387882002315931283307552259758800147230441364940067737629724267789495133437902185231440687109846850636144380099873463638315148991728298122033356354517921412768790740865868179278375935463048392519469202622915045481412671241987421006155396670134490999379703029675174589548207343841650869981851325196241444047250234125599598103239998585995003435281999839335940176071824247962961389497089327327497725429986186668543467719894908942685390446320023030644494888792734335849898918538685688454053767908976296753379165477119577825897131267426873248687497237940676210239068913731360228293327991344595664031846087759630256180839538046141510616706501435759274395074492737239546589191011825265221297230213113407905053245114975469507761237741252716023016260470388796964738289766026815163511275341310759465498403521699526552578327779978364339753539103925983007523130715981679444793621551254003594155990933627113710433187766855824763032328481821609981522995323775601660067979868543689950910771558188575614824884320291531130081713368878305671164144401501463917016330789088258627099319442346798040487546394222682945196169897678122308633516632481520048588413327114725257392611695319822521306898933431486130989380123132973200546145112501613860763961164027683677531746553281932494603192766043235184136987575004285157957347291407516598407343689788849000027681777020146941562819090521465853903811854912473780187569427059303569691239688356876285385441829200408668811291668355338422046120038530592736997263995352853510406606178161900271430260486275632363871121268209766506119107255034692395134860458356447308796298178429491189227348046782557199599017044379850398797772851403913604274404497600217231859689714328395216734651991029781551604386010268702873326592129516195314220175916235957656602799810046111918221402917414745282368997820806703127186276844630726953976875255195161257257319075658041632158018320237875357083613484244191625593969169991835475190404868792899856789744141735485933808780846282645970899043252195408318793407192346753305056858554955035617428147667291257376420490519985598470173245981700306819886605016154082799591718396811182795122049628127663693089678897058484344120014892180657724783423659283762005875893149289361758009442830801040526222802511211703797619917685260679066321810085589806342809419155630881493670905285273651051488871987838229475896525438272548797497325004317021206592508045130681843779873387648115145396794764253730384551192041490805543299434622566082819566840956059240359259422092818118468044672539431184682480797212751106343460228463154410535038609353005309678931023573616994307744692217360536990389550210200701573435931027347540196454936213769810671148404412223615520572218632290150503550262229923431327523223498309232393950533312573653055561534548638038709977398263046494823368718427645911415309575147408538155313289948864073891168785372366246092033364034382315123403014429556640696152658266639656713879763745246236626197433574954931221664721642059153213555257242955494082875660126139342676282117050032963208244872583652759654362232370969843838514694072344632981115705549975150035237442908165415953482238145709700068185291291182624067932812368836946585654697762476085419913877421015553394701943436023942626681029830621819635802035968408397132033204987326066462496270492442193129937764903947748057236079984942090085811796697515893497031233222424458214963467923817773833796092246403229376684841064812407392195643106855528153898552578975647515264391141590757002838217549771333080572479291608081471086839684393363959781303227800973418805165970224164863109262673380693123283652026359949310172842494916167727629907577603914788870895808086378487135848939465815992446666759955499287613176082495025655263545623049651708088465608807672415250914737391415915216568698609485866802599333253611388591072988853138639459124854036220702389513345272535852863644301319909716026107389789093813857049483073788037655190613779846391640006506684015130253187293455366423095892868921352183739412245018467245735291405219672798987951434998641655820424585667485828068464368255290550997313664923870637239703800729413742373776129343309561964997805248593325491309284487327187495939969046389275496307853321846727098472298990310911214938280922180252770281461833793056580065002023780671947942641419884325728802563687869358930014220871634917739603555710148983428863438167411817393567906102039229089663382604230426472249503840875940477760383483433772228298889410130137267926757005707598315868485052225843223369843968905660212548984746297595406125511988967447010051189813275351343889432865148251815483959062920150929451022129734494967438666905957638421663656948438230354319416028476482048144126344802322906884296733697132614276938798391848542068166859847798524831859116492171441919187980218322822257273742209292239746731744988000264422498309120936906391441603359375304540069734162268162925233132656672595523084930252863420160448634252247599695450345769583974243550592422809715500858375066492685563281227198972321717827736013279283363803246564461020118956778355080222185342251993586975868305564825140996333627125081895710898511961124349723701631075283264681461930323159031540154639479318811922654211937374493213348179009965346095844148767130950414052262238815591217769189301815563857210754615156374402454183333664425388069338837105351435288734523947127030091239221521007804455506865379592052149682784289139311857692109034185195885297365347820735539654310251019577263213568843100235162765279827417017464613118177790427177620809576312555845578072634346774617436195897860393302784647219295622359696175954511768156452271039521674595348396891223248672125813871988501766986020618939585319131474082498224900078775038788200231593128330755225
explicit
keywordstd::stringstream