Posted: Sat Apr 02, 2005 4:31 pm
My program prints 205 lines, the last one "1 204 20706 1394204..."
Code: Select all
This is the last but one line....
1 203 20503 1373701 68685050 2733664990 90210944670 2538793728570 62200446349965 1347676337582575 26144920949101955 458724522106970665 7339592353711530640 107835549196838642480 1463482453385667290800 18439878912659407864080 216668577223748042402940 2383354349461228466432340 24627994944432694153134180 239798898143160443069990700 2206149862917076076243914440 19225020233991662950125540120 159043349208476484405584013720 1251602008988445377278726368840 9387015067413340329590447766300 67211027882679516759867606006708 460137037042959768586785918045924 3016453909503847371846707684967724 18960567431167040623036448305511408 114417217257042486518323394947051600 663619860090846421806275690692899280 3703426961152142934596312725479728240 19905919916192768273455180899453539290 103148857747544344689722301024441067230 515744288737721723448611505122205336150 2490308137047856321794724124732934337410 11621437972889996168375379248753693574580 52453517337098090814018603636266670998780 229139049419954817766502321147901773310460 969434439853654998242894435625738271698100 3974681203399985492795867186065526913962210 15801781369614576471359179300699533828679030 60949728139941937818099691588412487624904830 228207121640247720667768612691497918781620410 829844078691809893337340409787265159205892400 2932115744711061623125269447915003562527486480 10071180166616255140299838538490664410420497040 33642027365079831000576056394532644945447192240 109336588936509450751872183282231096072703374780 345860638472631936051840579770322854923857614100 1065250766495706363039668985692594393165481451428 3195752299487119089119006957077783179496444354284 9341429798500809645117097259150443140066529650984 26614262256106080309673239360975790833019735420728 73928506266961334193536776002710530091721487279800 200279044250495250815217811352797617884845483721640 529308902662023162868789930003822275838520206978620 1365059801602059735819510872115120606109867902208020 3436185017825874507407734264289786353311046788316740 8444861484487318704646126581729135953052572615354700 20267667562769564891150703796149926287326174276851280 47512728876656520974336895784417040312912179042454640 108819475814277838360578051635277737490863377806912240 243548350631955162045103258421812079146218036044041680 532762017007401916973663377797713923132351953846341175 1139291082523521022451372454059726697159952639763714205 2382154081640089410580142403943064912243537337687766065 4870971778876003720141485214032834223542755451689909715 9741943557752007440282970428065668447085510903379819430 19060324352123492817944942141867612179080347419656168450 36486906616922114822923174957289429028525236489056093890 68348712395079454527447637596049212123857133141471274470 125305972724312333300320668926090222227071410759364003195 224864142834039940580027501771476974133511709718858690665 395031602276016111829778043652594684288601652208805807925 679454355914747712347218235082462856976394841799145989631 1144344178382732989216367553823095338065507101977509035168 1887424813696195969226995835526403999147005220144722694368 3048917006740008873366685580465729537083623817156859737056 4824235770158241888238426551369825216904468065121613508000 7477565443745274926769561154623229086201925500938500937400 11354821599761343407316741012576014538306627612536242164200 16893758965498584093812712238222850898456202057675872488200 24628251021991911751220941937650180225460246373238320133400 35183215745702731073172774196643114607800351961769028762000 49256502043983823502441883875300360450920492746476640266800 67584502804535943875443515084714448060565327256793529668400 90889503771617303832493003044960809460760267690170608864400 119808891335313718688286231286539248834638534682497620775800 154809241613045816282617040426427119280712713353789060553000 196091706043191367291314917873474351088902770248132810033800 243498492119567302240863579337391227176329813604824258613400 296432946928168889684529574845519754823358033953699097442400 353807065688459642526696589331749384789169266331834406624800 414029544954580432744006647090345024753283184005338135412000 475044425263676496516807626661553765243240705858756386946400 534424978421636058581408579994247985898645794091100935314700 589520337021804724414543485148294170011908247090183505965700 637644446166441844774914381895093694094513001954688281962900 676289564115923168700666768676614524039635002073154238445500 703341146680560095448693439423679105001220402156080407983320 717268694139581087437776477828108394209165360614616653685960 717268694139581087437776477828108394209165360614616653685960 703341146680560095448693439423679105001220402156080407983320 676289564115923168700666768676614524039635002073154238445500 637644446166441844774914381895093694094513001954688281962900 589520337021804724414543485148294170011908247090183505965700 534424978421636058581408579994247985898645794091100935314700 475044425263676496516807626661553765243240705858756386946400 414029544954580432744006647090345024753283184005338135412000 353807065688459642526696589331749384789169266331834406624800 296432946928168889684529574845519754823358033953699097442400 243498492119567302240863579337391227176329813604824258613400 196091706043191367291314917873474351088902770248132810033800 154809241613045816282617040426427119280712713353789060553000 119808891335313718688286231286539248834638534682497620775800 90889503771617303832493003044960809460760267690170608864400 67584502804535943875443515084714448060565327256793529668400 49256502043983823502441883875300360450920492746476640266800 35183215745702731073172774196643114607800351961769028762000 24628251021991911751220941937650180225460246373238320133400 16893758965498584093812712238222850898456202057675872488200 11354821599761343407316741012576014538306627612536242164200 7477565443745274926769561154623229086201925500938500937400 4824235770158241888238426551369825216904468065121613508000 3048917006740008873366685580465729537083623817156859737056 1887424813696195969226995835526403999147005220144722694368 1144344178382732989216367553823095338065507101977509035168 679454355914747712347218235082462856976394841799145989631 395031602276016111829778043652594684288601652208805807925 224864142834039940580027501771476974133511709718858690665 125305972724312333300320668926090222227071410759364003195 68348712395079454527447637596049212123857133141471274470 36486906616922114822923174957289429028525236489056093890 19060324352123492817944942141867612179080347419656168450 9741943557752007440282970428065668447085510903379819430 4870971778876003720141485214032834223542755451689909715 2382154081640089410580142403943064912243537337687766065 1139291082523521022451372454059726697159952639763714205 532762017007401916973663377797713923132351953846341175 243548350631955162045103258421812079146218036044041680 108819475814277838360578051635277737490863377806912240 47512728876656520974336895784417040312912179042454640 20267667562769564891150703796149926287326174276851280 8444861484487318704646126581729135953052572615354700 3436185017825874507407734264289786353311046788316740 1365059801602059735819510872115120606109867902208020 529308902662023162868789930003822275838520206978620 200279044250495250815217811352797617884845483721640 73928506266961334193536776002710530091721487279800 26614262256106080309673239360975790833019735420728 9341429798500809645117097259150443140066529650984 3195752299487119089119006957077783179496444354284 1065250766495706363039668985692594393165481451428 345860638472631936051840579770322854923857614100 109336588936509450751872183282231096072703374780 33642027365079831000576056394532644945447192240 10071180166616255140299838538490664410420497040 2932115744711061623125269447915003562527486480 829844078691809893337340409787265159205892400 228207121640247720667768612691497918781620410 60949728139941937818099691588412487624904830 15801781369614576471359179300699533828679030 3974681203399985492795867186065526913962210 969434439853654998242894435625738271698100 229139049419954817766502321147901773310460 52453517337098090814018603636266670998780 11621437972889996168375379248753693574580 2490308137047856321794724124732934337410 515744288737721723448611505122205336150 103148857747544344689722301024441067230 19905919916192768273455180899453539290 3703426961152142934596312725479728240 663619860090846421806275690692899280 114417217257042486518323394947051600 18960567431167040623036448305511408 3016453909503847371846707684967724 460137037042959768586785918045924 67211027882679516759867606006708 9387015067413340329590447766300 1251602008988445377278726368840 159043349208476484405584013720 19225020233991662950125540120 2206149862917076076243914440 239798898143160443069990700 24627994944432694153134180 2383354349461228466432340 216668577223748042402940 18439878912659407864080 1463482453385667290800 107835549196838642480 7339592353711530640 458724522106970665 26144920949101955 1347676337582575 62200446349965 2538793728570 90210944670 2733664990 68685050 1373701 20503 203 1
This is the last line ...
1 204 20706 1394204 70058751 2802350040 92944609660 2629004673240 64739240078535 1409876783932540 27492597286684530 484869443056072620 7798316875818501305 115175141550550173120 1571318002582505933280 19903361366045075154880 235108456136407450267020 2600022926684976508835280 27011349293893922619566520 264426893087593137223124880 2445948761060236519313905140 21431170096908739026369454560 178268369442468147355709553840 1410645358196921861684310382560 10638617076401785706869174135140 76598042950092857089458053773008 527348064925639285346653524052632 3476590946546807140433493603013648 21977021340670887994883155990479132 133377784688209527141359843252563008 778037077347888908324599085639950880 4367046821242989356402588416172627520 23609346877344911208051493624933267530 123054777663737112963177481923894606520 618893146485266068138333806146646403380 3006052425785578045243335629855139673560 14111746109937852490170103373486627911990 64074955309988086982393982885020364573360 281592566757052908580520924784168444309240 1198573489273609816009396756773640045008560 4944115643253640491038761621691265185660310 19776462573014561964155046486765060742641240 76751509509556514289458870889112021453583860 289156849780189658485868304279910406406525240 1058051200332057614005109022478763077987512810 3761959823402871516462609857702268721733378880 13003295911327316763425107986405667972947983520 43713207531696086140875894933023309355867689280 142978616301589281752448239676763741018150567020 455197227409141386803712763052553950996560988880 1411111404968338299091509565462917248089339065528 4261003065982825452158675942770377572661925805712 12537182097987928734236104216228226319562974005268 35955692054606889954790336620126233973086265071712 100542768523067414503210015363686320924741222700528 274207550517456585008754587355508147976566971001440 729587946912518413684007741356619893723365690700260 1894368704264082898688300802118942881948388109186640 4801244819427934243227245136404906959420914690524760 11881046502313193212053860846018922306363619403671440 28712529047256883595796830377879062240378746892205980 67780396439426085865487599580566966600238353319305920 156332204690934359334914947419694777803775556849366880 352367826446233000405681310057089816637081413850953920 776310367639357079018766636219526002278569989890382855 1672053099530922939425035831857440620292304593610055380 3521445164163610433031514858002791609403489977451480270 7253125860516093130721627617975899135786292789377675780 14612915336628011160424455642098502670628266355069729145 28802267909875500258227912569933280626165858323035987880 55547230969045607640868117099157041207605583908712262340 104835619012001569350370812553338641152382369630527368360 193654685119391787827768306522139434350928543900835277665 350170115558352273880348170697567196360583120478222693860 619895745110056052409805545424071658422113361927664498590 1074485958190763824176996278735057541264996494007951797556 1823798534297480701563585788905558195041901943776655024799 3031768992078928958443363389349499337212512322122231729536 4936341820436204842593681415992133536230629037301582431424 7873152776898250761605112131835554753988091882278473245056 12301801213903516815007987705993054303106393566060114445400 18832387043506618334086302167199243624508553113474743101600 28248580565259927501129453250798865436762829670212114652400 41522009987490495845033654175873031123916448430914192621600 59811466767694642824393716134293294833260598335007348895400 84439717789686554575614658071943475058720844708245669028800 116841004848519767377885398960014808511485820003270169935200 158474006576153247707936518129675257521325594946964138532800 210698395106931022520779234331500058295398802372668229640200 274618132948359534970903271712966368115351248036286681328800 350900947656237183573931958299901470369615483601921870586800 439590198162758669532178497210865578265232583852957068647200 539931439047736191925393154182910981999687847558523356055800 650240012616628532211226164177269139612527300285533504067200 767836610643040075270703236422094409542452450337172542036800 889073970218256929260814273751898789996523889864094522358400
I stopped my code when any number exceeds 10^61.When any number in the triangle is exceeds or equals 10^60, your program should finish printing the current row and exit.
Code: Select all
1 204 20706 1394204 70058751 2802350040 92944609660 2629004673240 64739240078535 1409876783932540 27492597286684530 484869443056072620 7798316875818501305 115175141550550173120 1571318002582505933280 19903361366045075154880 235108456136407450267020 2600022926684976508835280 27011349293893922619566520 264426893087593137223124880 2445948761060236519313905140 21431170096908739026369454560 178268369442468147355709553840 1410645358196921861684310382560 10638617076401785706869174135140 76598042950092857089458053773008 527348064925639285346653524052632 3476590946546807140433493603013648 21977021340670887994883155990479132 133377784688209527141359843252563008 778037077347888908324599085639950880 4367046821242989356402588416172627520 23609346877344911208051493624933267530 123054777663737112963177481923894606520 618893146485266068138333806146646403380 3006052425785578045243335629855139673560 14111746109937852490170103373486627911990 64074955309988086982393982885020364573360 281592566757052908580520924784168444309240 1198573489273609816009396756773640045008560 4944115643253640491038761621691265185660310 19776462573014561964155046486765060742641240 76751509509556514289458870889112021453583860 289156849780189658485868304279910406406525240 1058051200332057614005109022478763077987512810 3761959823402871516462609857702268721733378880 13003295911327316763425107986405667972947983520 43713207531696086140875894933023309355867689280 142978616301589281752448239676763741018150567020 455197227409141386803712763052553950996560988880 1411111404968338299091509565462917248089339065528 4261003065982825452158675942770377572661925805712 12537182097987928734236104216228226319562974005268 35955692054606889954790336620126233973086265071712 100542768523067414503210015363686320924741222700528 274207550517456585008754587355508147976566971001440 729587946912518413684007741356619893723365690700260 1894368704264082898688300802118942881948388109186640 4801244819427934243227245136404906959420914690524760 11881046502313193212053860846018922306363619403671440 28712529047256883595796830377879062240378746892205980 67780396439426085865487599580566966600238353319305920 156332204690934359334914947419694777803775556849366880 352367826446233000405681310057089816637081413850953920 776310367639357079018766636219526002278569989890382855 1672053099530922939425035831857440620292304593610055380 3521445164163610433031514858002791609403489977451480270 7253125860516093130721627617975899135786292789377675780 14612915336628011160424455642098502670628266355069729145 28802267909875500258227912569933280626165858323035987880 55547230969045607640868117099157041207605583908712262340 104835619012001569350370812553338641152382369630527368360 193654685119391787827768306522139434350928543900835277665 350170115558352273880348170697567196360583120478222693860 619895745110056052409805545424071658422113361927664498590 1074485958190763824176996278735057541264996494007951797556 1823798534297480701563585788905558195041901943776655024799 3031768992078928958443363389349499337212512322122231729536 4936341820436204842593681415992133536230629037301582431424 7873152776898250761605112131835554753988091882278473245056 12301801213903516815007987705993054303106393566060114445400 18832387043506618334086302167199243624508553113474743101600 28248580565259927501129453250798865436762829670212114652400 41522009987490495845033654175873031123916448430914192621600 59811466767694642824393716134293294833260598335007348895400 84439717789686554575614658071943475058720844708245669028800 116841004848519767377885398960014808511485820003270169935200 158474006576153247707936518129675257521325594946964138532800 210698395106931022520779234331500058295398802372668229640200 274618132948359534970903271712966368115351248036286681328800 350900947656237183573931958299901470369615483601921870586800 439590198162758669532178497210865578265232583852957068647200 539931439047736191925393154182910981999687847558523356055800 650240012616628532211226164177269139612527300285533504067200 767836610643040075270703236422094409542452450337172542036800 889073970218256929260814273751898789996523889864094522358400 1009469403685312555098216206655801751141886499949857322261100 1123945315443440782995952065142542155910554041181284441280400 1227164783188246569189457867043387864106421249044871787928600 1313934010282365013475581150571708218134148004027842520408400 1379630710796483264149360208100293629040855404229234646428820 1420609840820141182886469917251787499210385762770697061669280 1434537388279162174875552955656216788418330721229233307371920 1420609840820141182886469917251787499210385762770697061669280 1379630710796483264149360208100293629040855404229234646428820 1313934010282365013475581150571708218134148004027842520408400 1227164783188246569189457867043387864106421249044871787928600 1123945315443440782995952065142542155910554041181284441280400 1009469403685312555098216206655801751141886499949857322261100 889073970218256929260814273751898789996523889864094522358400 767836610643040075270703236422094409542452450337172542036800 650240012616628532211226164177269139612527300285533504067200 539931439047736191925393154182910981999687847558523356055800 439590198162758669532178497210865578265232583852957068647200 350900947656237183573931958299901470369615483601921870586800 274618132948359534970903271712966368115351248036286681328800 210698395106931022520779234331500058295398802372668229640200 158474006576153247707936518129675257521325594946964138532800 116841004848519767377885398960014808511485820003270169935200 84439717789686554575614658071943475058720844708245669028800 59811466767694642824393716134293294833260598335007348895400 41522009987490495845033654175873031123916448430914192621600 28248580565259927501129453250798865436762829670212114652400 18832387043506618334086302167199243624508553113474743101600 12301801213903516815007987705993054303106393566060114445400 7873152776898250761605112131835554753988091882278473245056 4936341820436204842593681415992133536230629037301582431424 3031768992078928958443363389349499337212512322122231729536 1823798534297480701563585788905558195041901943776655024799 1074485958190763824176996278735057541264996494007951797556 619895745110056052409805545424071658422113361927664498590 350170115558352273880348170697567196360583120478222693860 193654685119391787827768306522139434350928543900835277665 104835619012001569350370812553338641152382369630527368360 55547230969045607640868117099157041207605583908712262340 28802267909875500258227912569933280626165858323035987880 14612915336628011160424455642098502670628266355069729145 7253125860516093130721627617975899135786292789377675780 3521445164163610433031514858002791609403489977451480270 1672053099530922939425035831857440620292304593610055380 776310367639357079018766636219526002278569989890382855 352367826446233000405681310057089816637081413850953920 156332204690934359334914947419694777803775556849366880 67780396439426085865487599580566966600238353319305920 28712529047256883595796830377879062240378746892205980 11881046502313193212053860846018922306363619403671440 4801244819427934243227245136404906959420914690524760 1894368704264082898688300802118942881948388109186640 729587946912518413684007741356619893723365690700260 274207550517456585008754587355508147976566971001440 100542768523067414503210015363686320924741222700528 35955692054606889954790336620126233973086265071712 12537182097987928734236104216228226319562974005268 4261003065982825452158675942770377572661925805712 1411111404968338299091509565462917248089339065528 455197227409141386803712763052553950996560988880 142978616301589281752448239676763741018150567020 43713207531696086140875894933023309355867689280 13003295911327316763425107986405667972947983520 3761959823402871516462609857702268721733378880 1058051200332057614005109022478763077987512810 289156849780189658485868304279910406406525240 76751509509556514289458870889112021453583860 19776462573014561964155046486765060742641240 4944115643253640491038761621691265185660310 1198573489273609816009396756773640045008560 281592566757052908580520924784168444309240 64074955309988086982393982885020364573360 14111746109937852490170103373486627911990 3006052425785578045243335629855139673560 618893146485266068138333806146646403380 123054777663737112963177481923894606520 23609346877344911208051493624933267530 4367046821242989356402588416172627520 778037077347888908324599085639950880 133377784688209527141359843252563008 21977021340670887994883155990479132 3476590946546807140433493603013648 527348064925639285346653524052632 76598042950092857089458053773008 10638617076401785706869174135140 1410645358196921861684310382560 178268369442468147355709553840 21431170096908739026369454560 2445948761060236519313905140 264426893087593137223124880 27011349293893922619566520 2600022926684976508835280 235108456136407450267020 19903361366045075154880 1571318002582505933280 115175141550550173120 7798316875818501305 484869443056072620 27492597286684530 1409876783932540 64739240078535 2629004673240 92944609660 2802350040 70058751 1394204 20706 204 1
Code: Select all
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int max(int x,int y){
if(x>y){
return x;
}
return y;
}
const int SX=300;
void addup(string &stra,string &strb){
int carry=0;
string strtemp="";
reverse(stra.begin(),stra.end());
reverse(strb.begin(),strb.end());
bool aout=false,bout=false;
for(int x=0;x<=max(stra.size(),strb.size())-1 || carry>0;x++){
if(stra[x]==0x00){
aout=true;
}
if(strb[x]==0x00){
bout=true;
}
if(!aout){
carry+=stra[x]-0x30;
}
if(!bout){
carry+=strb[x]-0x30;
}
strtemp+=char(carry%10+0x30);
carry/=10;
}
reverse(strtemp.begin(),strtemp.end());
reverse(strb.begin(),strb.end());
stra=strtemp;
}
int main(){
string pnum[SX+1];
int i;
for(int num=0;;num++){
//next num
pnum[num]="1";
for(i=num-1;i>=1;i--){
addup(pnum[i],pnum[i-1]);
}
//output
bool out=false;
for(i=0;i<=num-1;i++){
if(pnum[i].size()>=61){
out=true;
}
cout<<pnum[i]<<" ";
}
cout<<"1"<<endl;
if(out){
break;
}
}
return 0;
}
This is wrong.swpeng wrote: if(stra[x]==0x00){
aout=true;
}
if(strb[x]==0x00){
bout=true;
}
Code: Select all
aout=!(x<stra.size());
bout=!(x<strb.size());
mf wrote:This is wrong.swpeng wrote: if(stra[x]==0x00){
aout=true;
}
if(strb[x]==0x00){
bout=true;
}
A correct way to implement this check:Code: Select all
aout=!(x<stra.size()); bout=!(x<strb.size());