468,463 Members | 1,957 Online

# factorial of very big number like 4096

Hi

How to write a program to get the factorial of 4096.
I am working on a Linux m/c.

Best Regards,
Subra

Sep 5 '06 #1
58 6250
ma*********@gmail.com wrote:
Hi

How to write a program to get the factorial of 4096.
I am working on a Linux m/c.
The simplest and ***out of topic*** answer is to
write
echo 'a=1 ; for (b=1;b<4097;b++) {a = a *b} ; a' | bc

But since you posted here I assume that you want to do
and use that. (I'm assuming that you know how to write
a programme which calculates a smaller factorial.) I have
not directly used any bignums libraries myself so I can't
recomment any from experience but one can be found
at http://www.swox.com/gmp/#WHAT

Bear in mind that discussion of libraries outside the C
standard is out of topic for this group. If you want to do
everything from scratch then you would need to write
your own function for multiplication of integers of
unlimited size which is not particularly hard but I don't
have any quick advice on how to do it.

Sep 5 '06 #2
ma*********@gmail.com said:
Hi

How to write a program to get the factorial of 4096.
#include <stdio.h>

int main(void)
{
const char *f4096[] =
{
"3642736389457041931565827470311646920571244923509 8",
"5542995093848478037874935832413874911388522601924 1",
"4089162355975180441627205998905094740308390559314 4",
"6071408647808655638770830168587442912226200287365 1",
"8359143885077476828236052811215226577977366900003 4",
"8651608440700612480475773480267025200325557327190 9",
"4050704054890959391116443328821272992068767675402 8",
"7827143344139131740972056353826154697115312092071 0",
"4887512360271750820233149035678050047954536544090 5",
"6129169486367058787251575442320034279248825234876 8",
"8053953194328835298217036438745983226072486172401 0",
"7308643234077839152872443674376344680168556883326 3",
"7386395804976934864999134989517891049089754414574 0",
"9757087583463448077112563058862371618900940163633 0",
"5364699379880585861641517781619567282556771670461 4",
"5839697862534080392365848543569086431779530769313 0",
"1027201621640265991660426111519501968931122679609 3",
"9492845839807810011344222861314390416395627472289 9",
"4322791823811758014317294362366477888280548301387 7",
"5105564028503534206213046181660639686595689630286 6",
"4159819485546116512196074650312777859190864535253 6",
"9764691422119043907820834572301551490023249021144 9",
"6694453040301645114156085038405713871745252163181 0",
"1241411784733092415770606466122348631473332743165 1",
"5547965567202587410505548126387400545963209196781 3",
"5257157165896931704333085482371580601686017982399 2",
"1062509485140759676999941304914726642121522117853 8",
"8445397095686405550234908748792776199429556965412 9",
"3033197148703450477211713369242157726411517927388 5",
"9061623728613712013704292298845400304784983376067 3",
"0162231702483984478426062605927221744900553588383 9",
"2125829991214836449889162856310294197119997515028 8",
"1943179452543718092338181644298378930670388563857 4",
"3430650443957286701137163559929647767365749711995 6",
"8205480928431052193293749489177156862427223816287 2",
"5473399737282871555676309574425452170828672424055 5",
"0137338990387798268304420523442087533579528879770 2",
"1815033676959461231434905044519497978446883785603 7",
"9172070932031166288568104169400035549594096556664 0",
"0214595093708151980595718786630026750079140913951 0",
"5579429388210632420577931871329120168819948075375 4",
"9168956483672965229553667546806013780633218260457 3",
"6314709460562086129682243442338989948364714455480 2",
"3771674088047295116853014562072695023735534150590 1",
"2382982902317532039089848971461619107915250016014 8",
"3123623853865481489994692396302595886857159401444 5",
"8215501540896469816033400931820262017453457576313 6",
"5825890562955665695866249766545433291955103886898 3",
"2676298968653964289696725213410134814965986188239 6",
"0785897291905907636941294725118003292772188372632 9",
"4996066415850331313644806862951193592965131296997 1",
"1336614096490401285257590291661290980876928725046 2",
"8099670816498692264864662073433571689768351150810 2",
"3710074968491481787167965221695061227123235540313 4",
"0851542159876278346592949488517883671050986695486 5",
"7248660045515752134569765362846212796284409822804 2",
"1009388709727106261888628088781019195673954735697 4",
"7394772248759615801868615498248241969585893942202 4",
"9002098851590676178657798938038215126965439162933 1",
"6402245896260653418982702638652755957965204542075 3",
"0864806669550604593959497668022385129293967398828 2",
"7244777215807217286605754761993027464606060793409 2",
"4831948868825984164049363959026470761061838128576 2",
"3820327031104789909390237308329836389890419589738 8",
"2775936476920301428047744707561614824394442871976 3",
"9688308263084311048740281453764679122813089504651 5",
"0459143919642755922311496017798532175043462854993 2",
"1346930041336747875962981022858924946156006022480 4",
"4542843606290903098335417082646069041169972666924 5",
"4972597563961164186482570253929504419917381556642 8",
"0464228672219626440161050938738949600773145044547 8",
"6024326205903555792821201896645251395145406733590 9",
"3715166487503429694759043853343951147988454386486 5",
"2070589306591735448823750935347565722954365113052 2",
"6235942518314914651560658628855280859475522866294 0",
"1378023265224608879674274441048782398989340415849 6",
"3997626302189888067973676230201690561635628959074 0",
"4607399186021943145098762844103652664444215328246 7",
"6777193841248117516465255471727467953723776997658 3",
"8269715139709926420324071644994002695873706011010 0",
"8414035841791363153469820670961469421309100374885 0",
"5191747542199119351522748309506094862401224772749 4",
"9948175361325803965893668756476999198477393569483 9",
"8356858801556893888992541040897907895478043405927 3",
"7856689290102536070724323042938540661980110480834 3",
"1288219540451429167083096797393656114876886620827 0",
"7296821112533351516773050343991015788576132619057 5",
"8891785774574890530337175259209913670316515128233 3",
"1004944993233471280319484976902881766394475461525 9",
"9173772000911565297841828485300937253530263374116 7",
"2268229512816703234469473013717497514201150239804 5",
"5620924032300629560206166445878040058150999740691 0",
"1832210673757163925038369891489885518417662205452 2",
"4200014520786041958657772212886287623699665395020 4",
"9672383011548039199455120250348602003212025393162 3",
"3694006359168439408091255927642403518104559241292 7",
"6260647990497584144884059775730132635041055992520 9",
"0446182272325256729137346978179219678246752223880 8",
"8469251797881683841017624251086627182469529353956 5",
"6211871075027661525115056574989229278462121279602 0",
"0180369732511088739805534344947312318447795091991 5",
"6425126867642335584966826615948149370085667363667 2",
"6252122893912770756806014510219724102649607576555 6",
"7603555819188991771808172057954892007215261170873 7",
"2624117239376321826022971881460357421847399820715 7",
"0801670479278475162293202050787880044673572722755 7",
"6623074184484920981754172406980963360979187075078 6",
"4111077201409485063944534116895584857326872966600 7",
"2059346024119930247050075128009914605422904014587 7",
"5056425199199293879762658289393632779108744631811 8",
"2582863491881836466883505365868368773965487008925 0",
"7990531560129263973262495134256801574600567920692 6",
"1847141849344594437514603375088484154934859399450 4",
"0364392732180366366127593333269974441195904903747 6",
"3885950904588235516095627241991827914945184992195 9",
"0644637893576786219670656962453751416566885966000 7",
"9710601159738845180455640872137856516052143426080 7",
"6512767696951925126056836246123394196832666170078 0",
"7585238172448106626580825372163351752798357923691 9",
"1178240098100419413147173712094102904713045233504 6",
"0108353663941632303245322351511318363499981049071 7",
"8262819354606145923371057127413957229079506399247 9",
"3004744205529198456937272256809090392287760090550 2",
"0062755689711145888359374314904797355195355920178 7",
"3975992754635045877182883946369955211136725311999 9",
"2946177300087506730555715836349188418791268609333 4",
"0003348125367064143929540683097124196149393297781 2",
"4590484559274421546432997872869679550425201820588 8",
"3198785742379247848095607930639582473884415786821 2",
"7801227243244710960451860367473571740951255318516 3",
"1062416897458269485706881498083546029121123795761 9",
"2823388648067282293125326481915414311674342632630 8",
"8962360660220908194636325830332763843958767886729 0",
"7512283546259944684635596887511928674690753598900 0",
"9591510953029341306696547410913370809008734445400 2",
"7294075072774399016106452193322795462050856526594 2",
"8993425095900583129656114076586926168599520907237 5",
"1579193885650392415200498948648865297913809981647 0",
"9030928808152894832968443475752787017835456323447 1",
"1640083988043013423170493495843625211966405184791 6",
"9013027086126006304484391864700337325452898300226 3",
"4101780354511975660474516777810015304940606898891 7",
"2831358155330093304553073031519209150437455115786 8",
"9279895194137995559051432273878334677189236984818 0",
"6937659201108818891889533980728331394636689918099 5",
"2346163400688357827545954559967898642295645786741 1",
"7297379445563554743001957415367741699994020499899 4",
"6839224443972914426272175211505486215732997486266 4",
"7720871722457646746446585504950815942621654065732 5",
"2849571014476728078068197500593134386186885299922 7",
"1651457838222483124474400252361004538800428957057 5",
"1389247786408261926539493092831106767328385056104 7",
"3411909026225654193551327237427822253336035652600 1",
"5181988532782682353519070469137913545766352207722 9",
"9065755245339664536104617507130000299418224976537 8",
"4398818177575817576691547329920957089391328999018 2",
"6058207518429093154503900538921282783754480683427 4",
"0887982153661592177649487051063875435823974487047 0",
"9113502513103752567914712686753723073170811307274 2",
"8307267973310427295588807815693656586064129096790 0",
"9266060339461476868527944199151589902941967738761 9",
"4428695639326502530432441711794108087706101247063 8",
"5122158565947999825871168537720019016440330308199 2",
"5204925351466014615770749861793750685507032845268 3",
"7050775239207314136343103668345641850066930620573 6",
"8982077485892125042881239620476209127848751982862 2",
"2456780717439579938621246414756581890748398892938 9",
"0405387257092619412909200900955849890768384522548 6",
"8377172591226888243979445102003538241146222532496 2",
"0463392457557302224921732629181941791892054650145 6",
"2195500929283390504473685578955903222418236152656 1",
"4807146977267034428759491285735611726845558313762 6",
"5701163152286637155608646529110874557687162693983 9",
"6965268621808736124384684810104943490794325529495 9",
"6325160975106104206822936391355948745333861591962 9",
"3499579648733291992792851778889369765189231928086 3",
"0894325503659661962481013950905143579873709797102 3",
"6469556602169114946107397304378714216993342898728 0",
"5488751634810127654918579785467746109172416838021 8",
"2442382240220440155673836115638273906340241851438 3",
"7553716822460158240024380995306392778557861668930 1",
"2748129579184756313625455797647322137651541260924 3",
"2044933018278655473429952983562112364311891900867 6",
"3677061754273871244681952951484143880249573012954 7",
"9209289005664171497396770096067930625703140808350 3",
"4814958112292646526157517059810979326113718152255 9",
"0611596502962541178428883651861764598172628754705 8",
"1752438519477484578567778168313603258348377717633 5",
"9179146509493033011680825124924554011037223759078 3",
"3684516686606383771188152419039365179791248839613 7",
"7652571987683959622904718089890707844846177189198 6",
"4789286574282951392045706005361859109795215605215 8",
"9103696823650181481646314071505433723323926112283 8",
"3225697881990279647532295566423275888982784519564 5",
"9920820839003511725625489277171625260535007504831 5",
"1698930336515460033897238666492299125873236436117 4",
"2592582556155755951518749197988850729875916543688 9",
"9144516395075948680815983813883406392458307639334 1",
"7365699429618072480813278616381581651442226513812 1",
"2623229629513931799055727185173553990703982396436 6",
"4800163701511474565254714522486780648018460915420 4",
"0298639488947975281491789960879045251735099057423 8",
"0023107676728164986130437527136314204606330209454 3",
"6038149659885729503698222143941153962352560118794 9",
"6903984979791765537989903236726054939627432569065 8",
"4137441988285323199416592533725190606455350257032 4",
"7675754800805519440483471416431366987142639236783 7",
"3256617913964985024704846877378164630818308651454 5",
"9143722150559339053122892609537294089238806337761 3",
"7141814891759151958610169385694220175289739182805 8",
"5696923423268386307770172578848432210467786017951 2",
"0613514323070254165759045092472806728375363558685 6",
"6923411280588879686184578210501694526750633031717 4",
"4799431994231658234381655685921175667870264263950 1",
"6563193985322329322090540892520145213308630572882 3",
"3832533169921380020075136517685191523495232574357 0",
"1410122100536607823254511566455142166173051380647 6",
"5818147243083294802113471932282687286002243917812 3",
"9197106713839023251502632953675747400891318249648 8",
"9413507468603215887590779579575237709669201513584 2",
"4413016483038064583849116476056414730273792527807 7",
"8553358681362958954197689918556037304536580014138 5",
"4422709075866553163400366041672289760002771306724 1",
"2811873264639505207835166227875984511181175251474 5",
"2705772916218631124704408796202678436381602777370 0",
"4550194307723699102998768828138037952357415236721 6",
"0476690898455450453556099143013063913291525822657 5",
"1400812443664644975591387417404942221742785706120 3",
"1909293900990151879933169907348217644720636511605 3",
"0351996144569828629496706962497160465582258924387 1",
"7036107088900710172233832611921376929976624072191 8",
"3985465779106386931468924774955484102318260729202 2",
"5809806629202490509139539829520312977101778880298 3",
"5194791146992509163753105519984004703051111089110 5",
"7880796702619142508034517950087035996649017026620 7",
"7476238607201894008199372197378412754960851836322 1",
"0650060557541199686289523558506398426019209636937 5",
"7167812542928572723529819281088272070401517492491 5",
"7190137461910549106058492054773376295749315740021 2",
"5289786257826406506950853599802698047380034420736 0",
"0000000000000000000000000000000000000000000000000 0",
"0000000000000000000000000000000000000000000000000 0",
"0000000000000000000000000000000000000000000000000 0",
"0000000000000000000000000000000000000000000000000 0",
"0000000000000000000000000000000000000000000000000 0",
"0000000000000000000000000000000000000000000000000 0",
"0000000000000000000000000000000000000000000000000 0",
"0000000000000000000000000000000000000000000000000 0",
"0000000000000000000000000000000000000000000000000 0",
"0000000000000000000000000000000000000000000000000 0",
"0000000000000000000000000000000000000000000000000 0",
"0000000000000000000000000000000000000000000000000 0",
"0000000000000000000000000000000000000000000000000 0",
"0000000000000000000000000000000000000000000000000 0",
"0000000000000000000000000000000000000000000000000 0",
"0000000000000000000000000000000000000000000000000 0",
"0000000000000000000000000000000000000000000000000 0",
"0000000000000000000000000000000000000000000000000 0",
"0000000000000000000000000000000000000000000000000 0",
"0000000000000000000000000000000000000000000000000 0",
"00000000000000000000",
NULL
};
size_t i = 0;
while(f4096[i] != NULL)
{
printf("%s\n", f4096[i++]);
}
return 0;
}

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Sep 5 '06 #3

Richard Heathfield wrote:
What is the logic to fill the below structure ?
const char *f4096[] =
{
"3642736389457041931565827470311646920571244923509 8",
"5542995093848478037874935832413874911388522601924 1",
"4089162355975180441627205998905094740308390559314 4",
"6071408647808655638770830168587442912226200287365 1",
"8359143885077476828236052811215226577977366900003 4",
"8651608440700612480475773480267025200325557327190 9",
"4050704054890959391116443328821272992068767675402 8",
"7827143344139131740972056353826154697115312092071 0",
"4887512360271750820233149035678050047954536544090 5",
"6129169486367058787251575442320034279248825234876 8",
"8053953194328835298217036438745983226072486172401 0",
"7308643234077839152872443674376344680168556883326 3",
"7386395804976934864999134989517891049089754414574 0",
"9757087583463448077112563058862371618900940163633 0",
"5364699379880585861641517781619567282556771670461 4",
"5839697862534080392365848543569086431779530769313 0",
"1027201621640265991660426111519501968931122679609 3",
"9492845839807810011344222861314390416395627472289 9",
"4322791823811758014317294362366477888280548301387 7",
"5105564028503534206213046181660639686595689630286 6",
"4159819485546116512196074650312777859190864535253 6",
"9764691422119043907820834572301551490023249021144 9",
"6694453040301645114156085038405713871745252163181 0",
"1241411784733092415770606466122348631473332743165 1",
"5547965567202587410505548126387400545963209196781 3",
"5257157165896931704333085482371580601686017982399 2",
"1062509485140759676999941304914726642121522117853 8",
"8445397095686405550234908748792776199429556965412 9",
"3033197148703450477211713369242157726411517927388 5",
"9061623728613712013704292298845400304784983376067 3",
"0162231702483984478426062605927221744900553588383 9",
"2125829991214836449889162856310294197119997515028 8",
"1943179452543718092338181644298378930670388563857 4",
"3430650443957286701137163559929647767365749711995 6",
"8205480928431052193293749489177156862427223816287 2",
"5473399737282871555676309574425452170828672424055 5",
"0137338990387798268304420523442087533579528879770 2",
"1815033676959461231434905044519497978446883785603 7",
"9172070932031166288568104169400035549594096556664 0",
"0214595093708151980595718786630026750079140913951 0",
"5579429388210632420577931871329120168819948075375 4",
"9168956483672965229553667546806013780633218260457 3",
"6314709460562086129682243442338989948364714455480 2",
"3771674088047295116853014562072695023735534150590 1",
"2382982902317532039089848971461619107915250016014 8",
"3123623853865481489994692396302595886857159401444 5",
"8215501540896469816033400931820262017453457576313 6",
"5825890562955665695866249766545433291955103886898 3",
"2676298968653964289696725213410134814965986188239 6",
"0785897291905907636941294725118003292772188372632 9",
"4996066415850331313644806862951193592965131296997 1",
"1336614096490401285257590291661290980876928725046 2",
"8099670816498692264864662073433571689768351150810 2",
"3710074968491481787167965221695061227123235540313 4",
"0851542159876278346592949488517883671050986695486 5",
"7248660045515752134569765362846212796284409822804 2",
"1009388709727106261888628088781019195673954735697 4",
"7394772248759615801868615498248241969585893942202 4",
"9002098851590676178657798938038215126965439162933 1",
"6402245896260653418982702638652755957965204542075 3",
"0864806669550604593959497668022385129293967398828 2",
"7244777215807217286605754761993027464606060793409 2",
"4831948868825984164049363959026470761061838128576 2",
"3820327031104789909390237308329836389890419589738 8",
"2775936476920301428047744707561614824394442871976 3",
"9688308263084311048740281453764679122813089504651 5",
"0459143919642755922311496017798532175043462854993 2",
"1346930041336747875962981022858924946156006022480 4",
"4542843606290903098335417082646069041169972666924 5",
"4972597563961164186482570253929504419917381556642 8",
"0464228672219626440161050938738949600773145044547 8",
"6024326205903555792821201896645251395145406733590 9",
"3715166487503429694759043853343951147988454386486 5",
"2070589306591735448823750935347565722954365113052 2",
"6235942518314914651560658628855280859475522866294 0",
"1378023265224608879674274441048782398989340415849 6",
"3997626302189888067973676230201690561635628959074 0",
"4607399186021943145098762844103652664444215328246 7",
"6777193841248117516465255471727467953723776997658 3",
"8269715139709926420324071644994002695873706011010 0",
"8414035841791363153469820670961469421309100374885 0",
"5191747542199119351522748309506094862401224772749 4",
"9948175361325803965893668756476999198477393569483 9",
"8356858801556893888992541040897907895478043405927 3",
"7856689290102536070724323042938540661980110480834 3",
"1288219540451429167083096797393656114876886620827 0",
"7296821112533351516773050343991015788576132619057 5",
"8891785774574890530337175259209913670316515128233 3",
"1004944993233471280319484976902881766394475461525 9",
"9173772000911565297841828485300937253530263374116 7",
"2268229512816703234469473013717497514201150239804 5",
"5620924032300629560206166445878040058150999740691 0",
"1832210673757163925038369891489885518417662205452 2",
"4200014520786041958657772212886287623699665395020 4",
"9672383011548039199455120250348602003212025393162 3",
"3694006359168439408091255927642403518104559241292 7",
"6260647990497584144884059775730132635041055992520 9",
"0446182272325256729137346978179219678246752223880 8",
"8469251797881683841017624251086627182469529353956 5",
"6211871075027661525115056574989229278462121279602 0",
"0180369732511088739805534344947312318447795091991 5",
"6425126867642335584966826615948149370085667363667 2",
"6252122893912770756806014510219724102649607576555 6",
"7603555819188991771808172057954892007215261170873 7",
"2624117239376321826022971881460357421847399820715 7",
"0801670479278475162293202050787880044673572722755 7",
"6623074184484920981754172406980963360979187075078 6",
"4111077201409485063944534116895584857326872966600 7",
"2059346024119930247050075128009914605422904014587 7",
"5056425199199293879762658289393632779108744631811 8",
"2582863491881836466883505365868368773965487008925 0",
"7990531560129263973262495134256801574600567920692 6",
"1847141849344594437514603375088484154934859399450 4",
"0364392732180366366127593333269974441195904903747 6",
"3885950904588235516095627241991827914945184992195 9",
"0644637893576786219670656962453751416566885966000 7",
"9710601159738845180455640872137856516052143426080 7",
"6512767696951925126056836246123394196832666170078 0",
"7585238172448106626580825372163351752798357923691 9",
"1178240098100419413147173712094102904713045233504 6",
"0108353663941632303245322351511318363499981049071 7",
"8262819354606145923371057127413957229079506399247 9",
"3004744205529198456937272256809090392287760090550 2",
"0062755689711145888359374314904797355195355920178 7",
"3975992754635045877182883946369955211136725311999 9",
"2946177300087506730555715836349188418791268609333 4",
"0003348125367064143929540683097124196149393297781 2",
"4590484559274421546432997872869679550425201820588 8",
"3198785742379247848095607930639582473884415786821 2",
"7801227243244710960451860367473571740951255318516 3",
"1062416897458269485706881498083546029121123795761 9",
"2823388648067282293125326481915414311674342632630 8",
"8962360660220908194636325830332763843958767886729 0",
"7512283546259944684635596887511928674690753598900 0",
"9591510953029341306696547410913370809008734445400 2",
"7294075072774399016106452193322795462050856526594 2",
"8993425095900583129656114076586926168599520907237 5",
"1579193885650392415200498948648865297913809981647 0",
"9030928808152894832968443475752787017835456323447 1",
"1640083988043013423170493495843625211966405184791 6",
"9013027086126006304484391864700337325452898300226 3",
"4101780354511975660474516777810015304940606898891 7",
"2831358155330093304553073031519209150437455115786 8",
"9279895194137995559051432273878334677189236984818 0",
"6937659201108818891889533980728331394636689918099 5",
"2346163400688357827545954559967898642295645786741 1",
"7297379445563554743001957415367741699994020499899 4",
"6839224443972914426272175211505486215732997486266 4",
"7720871722457646746446585504950815942621654065732 5",
"2849571014476728078068197500593134386186885299922 7",
"1651457838222483124474400252361004538800428957057 5",
"1389247786408261926539493092831106767328385056104 7",
"3411909026225654193551327237427822253336035652600 1",
"5181988532782682353519070469137913545766352207722 9",
"9065755245339664536104617507130000299418224976537 8",
"4398818177575817576691547329920957089391328999018 2",
"6058207518429093154503900538921282783754480683427 4",
"0887982153661592177649487051063875435823974487047 0",
"9113502513103752567914712686753723073170811307274 2",
"8307267973310427295588807815693656586064129096790 0",
"9266060339461476868527944199151589902941967738761 9",
"4428695639326502530432441711794108087706101247063 8",
"5122158565947999825871168537720019016440330308199 2",
"5204925351466014615770749861793750685507032845268 3",
"7050775239207314136343103668345641850066930620573 6",
"8982077485892125042881239620476209127848751982862 2",
"2456780717439579938621246414756581890748398892938 9",
"0405387257092619412909200900955849890768384522548 6",
"8377172591226888243979445102003538241146222532496 2",
"0463392457557302224921732629181941791892054650145 6",
"2195500929283390504473685578955903222418236152656 1",
"4807146977267034428759491285735611726845558313762 6",
"5701163152286637155608646529110874557687162693983 9",
"6965268621808736124384684810104943490794325529495 9",
"6325160975106104206822936391355948745333861591962 9",
"3499579648733291992792851778889369765189231928086 3",
"0894325503659661962481013950905143579873709797102 3",
"6469556602169114946107397304378714216993342898728 0",
"5488751634810127654918579785467746109172416838021 8",
"2442382240220440155673836115638273906340241851438 3",
"7553716822460158240024380995306392778557861668930 1",
"2748129579184756313625455797647322137651541260924 3",
"2044933018278655473429952983562112364311891900867 6",
"3677061754273871244681952951484143880249573012954 7",
"9209289005664171497396770096067930625703140808350 3",
"4814958112292646526157517059810979326113718152255 9",
"0611596502962541178428883651861764598172628754705 8",
"1752438519477484578567778168313603258348377717633 5",
"9179146509493033011680825124924554011037223759078 3",
"3684516686606383771188152419039365179791248839613 7",
"7652571987683959622904718089890707844846177189198 6",
"4789286574282951392045706005361859109795215605215 8",
"9103696823650181481646314071505433723323926112283 8",
"3225697881990279647532295566423275888982784519564 5",
"9920820839003511725625489277171625260535007504831 5",
"1698930336515460033897238666492299125873236436117 4",
"2592582556155755951518749197988850729875916543688 9",
"9144516395075948680815983813883406392458307639334 1",
"7365699429618072480813278616381581651442226513812 1",
"2623229629513931799055727185173553990703982396436 6",
"4800163701511474565254714522486780648018460915420 4",
"0298639488947975281491789960879045251735099057423 8",
"0023107676728164986130437527136314204606330209454 3",
"6038149659885729503698222143941153962352560118794 9",
"6903984979791765537989903236726054939627432569065 8",
"4137441988285323199416592533725190606455350257032 4",
"7675754800805519440483471416431366987142639236783 7",
"3256617913964985024704846877378164630818308651454 5",
"9143722150559339053122892609537294089238806337761 3",
"7141814891759151958610169385694220175289739182805 8",
"5696923423268386307770172578848432210467786017951 2",
"0613514323070254165759045092472806728375363558685 6",
"6923411280588879686184578210501694526750633031717 4",
"4799431994231658234381655685921175667870264263950 1",
"6563193985322329322090540892520145213308630572882 3",
"3832533169921380020075136517685191523495232574357 0",
"1410122100536607823254511566455142166173051380647 6",
"5818147243083294802113471932282687286002243917812 3",
"9197106713839023251502632953675747400891318249648 8",
"9413507468603215887590779579575237709669201513584 2",
"4413016483038064583849116476056414730273792527807 7",
"8553358681362958954197689918556037304536580014138 5",
"4422709075866553163400366041672289760002771306724 1",
"2811873264639505207835166227875984511181175251474 5",
"2705772916218631124704408796202678436381602777370 0",
"4550194307723699102998768828138037952357415236721 6",
"0476690898455450453556099143013063913291525822657 5",
"1400812443664644975591387417404942221742785706120 3",
"1909293900990151879933169907348217644720636511605 3",
"0351996144569828629496706962497160465582258924387 1",
"7036107088900710172233832611921376929976624072191 8",
"3985465779106386931468924774955484102318260729202 2",
"5809806629202490509139539829520312977101778880298 3",
"5194791146992509163753105519984004703051111089110 5",
"7880796702619142508034517950087035996649017026620 7",
"7476238607201894008199372197378412754960851836322 1",
"0650060557541199686289523558506398426019209636937 5",
"7167812542928572723529819281088272070401517492491 5",
"7190137461910549106058492054773376295749315740021 2",
"5289786257826406506950853599802698047380034420736 0",
"0000000000000000000000000000000000000000000000000 0",
"0000000000000000000000000000000000000000000000000 0",
"0000000000000000000000000000000000000000000000000 0",
"0000000000000000000000000000000000000000000000000 0",
"0000000000000000000000000000000000000000000000000 0",
"0000000000000000000000000000000000000000000000000 0",
"0000000000000000000000000000000000000000000000000 0",
"0000000000000000000000000000000000000000000000000 0",
"0000000000000000000000000000000000000000000000000 0",
"0000000000000000000000000000000000000000000000000 0",
"0000000000000000000000000000000000000000000000000 0",
"0000000000000000000000000000000000000000000000000 0",
"0000000000000000000000000000000000000000000000000 0",
"0000000000000000000000000000000000000000000000000 0",
"0000000000000000000000000000000000000000000000000 0",
"0000000000000000000000000000000000000000000000000 0",
"0000000000000000000000000000000000000000000000000 0",
"0000000000000000000000000000000000000000000000000 0",
"0000000000000000000000000000000000000000000000000 0",
"0000000000000000000000000000000000000000000000000 0",
"00000000000000000000",
NULL
};
size_t i = 0;
while(f4096[i] != NULL)
{
printf("%s\n", f4096[i++]);
}
return 0;
}

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Sep 5 '06 #4

Richard Heathfield wrote:
What is the logic to fill the below array?
const char *f4096[] =
{
"3642736389457041931565827470311646920571244923509 8",
"5542995093848478037874935832413874911388522601924 1",
"4089162355975180441627205998905094740308390559314 4",
"6071408647808655638770830168587442912226200287365 1",
"8359143885077476828236052811215226577977366900003 4",
"8651608440700612480475773480267025200325557327190 9",
"4050704054890959391116443328821272992068767675402 8",
"7827143344139131740972056353826154697115312092071 0",
"4887512360271750820233149035678050047954536544090 5",
"6129169486367058787251575442320034279248825234876 8",
"8053953194328835298217036438745983226072486172401 0",
"7308643234077839152872443674376344680168556883326 3",
"7386395804976934864999134989517891049089754414574 0",
"9757087583463448077112563058862371618900940163633 0",
"5364699379880585861641517781619567282556771670461 4",
"5839697862534080392365848543569086431779530769313 0",
"1027201621640265991660426111519501968931122679609 3",
"9492845839807810011344222861314390416395627472289 9",
"4322791823811758014317294362366477888280548301387 7",
"5105564028503534206213046181660639686595689630286 6",
"4159819485546116512196074650312777859190864535253 6",
"9764691422119043907820834572301551490023249021144 9",
"6694453040301645114156085038405713871745252163181 0",
"1241411784733092415770606466122348631473332743165 1",
"5547965567202587410505548126387400545963209196781 3",
"5257157165896931704333085482371580601686017982399 2",
"1062509485140759676999941304914726642121522117853 8",
"8445397095686405550234908748792776199429556965412 9",
"3033197148703450477211713369242157726411517927388 5",
"9061623728613712013704292298845400304784983376067 3",
"0162231702483984478426062605927221744900553588383 9",
"2125829991214836449889162856310294197119997515028 8",
"1943179452543718092338181644298378930670388563857 4",
"3430650443957286701137163559929647767365749711995 6",
"8205480928431052193293749489177156862427223816287 2",
"5473399737282871555676309574425452170828672424055 5",
"0137338990387798268304420523442087533579528879770 2",
"1815033676959461231434905044519497978446883785603 7",
"9172070932031166288568104169400035549594096556664 0",
"0214595093708151980595718786630026750079140913951 0",
"5579429388210632420577931871329120168819948075375 4",
"9168956483672965229553667546806013780633218260457 3",
"6314709460562086129682243442338989948364714455480 2",
"3771674088047295116853014562072695023735534150590 1",
"2382982902317532039089848971461619107915250016014 8",
"3123623853865481489994692396302595886857159401444 5",
"8215501540896469816033400931820262017453457576313 6",
"5825890562955665695866249766545433291955103886898 3",
"2676298968653964289696725213410134814965986188239 6",
"0785897291905907636941294725118003292772188372632 9",
"4996066415850331313644806862951193592965131296997 1",
"1336614096490401285257590291661290980876928725046 2",
"8099670816498692264864662073433571689768351150810 2",
"3710074968491481787167965221695061227123235540313 4",
"0851542159876278346592949488517883671050986695486 5",
"7248660045515752134569765362846212796284409822804 2",
"1009388709727106261888628088781019195673954735697 4",
"7394772248759615801868615498248241969585893942202 4",
"9002098851590676178657798938038215126965439162933 1",
"6402245896260653418982702638652755957965204542075 3",
"0864806669550604593959497668022385129293967398828 2",
"7244777215807217286605754761993027464606060793409 2",
"4831948868825984164049363959026470761061838128576 2",
"3820327031104789909390237308329836389890419589738 8",
"2775936476920301428047744707561614824394442871976 3",
"9688308263084311048740281453764679122813089504651 5",
"0459143919642755922311496017798532175043462854993 2",
"1346930041336747875962981022858924946156006022480 4",
"4542843606290903098335417082646069041169972666924 5",
"4972597563961164186482570253929504419917381556642 8",
"0464228672219626440161050938738949600773145044547 8",
"6024326205903555792821201896645251395145406733590 9",
"3715166487503429694759043853343951147988454386486 5",
"2070589306591735448823750935347565722954365113052 2",
"6235942518314914651560658628855280859475522866294 0",
"1378023265224608879674274441048782398989340415849 6",
"3997626302189888067973676230201690561635628959074 0",
"4607399186021943145098762844103652664444215328246 7",
"6777193841248117516465255471727467953723776997658 3",
"8269715139709926420324071644994002695873706011010 0",
"8414035841791363153469820670961469421309100374885 0",
"5191747542199119351522748309506094862401224772749 4",
"9948175361325803965893668756476999198477393569483 9",
"8356858801556893888992541040897907895478043405927 3",
"7856689290102536070724323042938540661980110480834 3",
"1288219540451429167083096797393656114876886620827 0",
"7296821112533351516773050343991015788576132619057 5",
"8891785774574890530337175259209913670316515128233 3",
"1004944993233471280319484976902881766394475461525 9",
"9173772000911565297841828485300937253530263374116 7",
"2268229512816703234469473013717497514201150239804 5",
"5620924032300629560206166445878040058150999740691 0",
"1832210673757163925038369891489885518417662205452 2",
"4200014520786041958657772212886287623699665395020 4",
"9672383011548039199455120250348602003212025393162 3",
"3694006359168439408091255927642403518104559241292 7",
"6260647990497584144884059775730132635041055992520 9",
"0446182272325256729137346978179219678246752223880 8",
"8469251797881683841017624251086627182469529353956 5",
"6211871075027661525115056574989229278462121279602 0",
"0180369732511088739805534344947312318447795091991 5",
"6425126867642335584966826615948149370085667363667 2",
"6252122893912770756806014510219724102649607576555 6",
"7603555819188991771808172057954892007215261170873 7",
"2624117239376321826022971881460357421847399820715 7",
"0801670479278475162293202050787880044673572722755 7",
"6623074184484920981754172406980963360979187075078 6",
"4111077201409485063944534116895584857326872966600 7",
"2059346024119930247050075128009914605422904014587 7",
"5056425199199293879762658289393632779108744631811 8",
"2582863491881836466883505365868368773965487008925 0",
"7990531560129263973262495134256801574600567920692 6",
"1847141849344594437514603375088484154934859399450 4",
"0364392732180366366127593333269974441195904903747 6",
"3885950904588235516095627241991827914945184992195 9",
"0644637893576786219670656962453751416566885966000 7",
"9710601159738845180455640872137856516052143426080 7",
"6512767696951925126056836246123394196832666170078 0",
"7585238172448106626580825372163351752798357923691 9",
"1178240098100419413147173712094102904713045233504 6",
"0108353663941632303245322351511318363499981049071 7",
"8262819354606145923371057127413957229079506399247 9",
"3004744205529198456937272256809090392287760090550 2",
"0062755689711145888359374314904797355195355920178 7",
"3975992754635045877182883946369955211136725311999 9",
"2946177300087506730555715836349188418791268609333 4",
"0003348125367064143929540683097124196149393297781 2",
"4590484559274421546432997872869679550425201820588 8",
"3198785742379247848095607930639582473884415786821 2",
"7801227243244710960451860367473571740951255318516 3",
"1062416897458269485706881498083546029121123795761 9",
"2823388648067282293125326481915414311674342632630 8",
"8962360660220908194636325830332763843958767886729 0",
"7512283546259944684635596887511928674690753598900 0",
"9591510953029341306696547410913370809008734445400 2",
"7294075072774399016106452193322795462050856526594 2",
"8993425095900583129656114076586926168599520907237 5",
"1579193885650392415200498948648865297913809981647 0",
"9030928808152894832968443475752787017835456323447 1",
"1640083988043013423170493495843625211966405184791 6",
"9013027086126006304484391864700337325452898300226 3",
"4101780354511975660474516777810015304940606898891 7",
"2831358155330093304553073031519209150437455115786 8",
"9279895194137995559051432273878334677189236984818 0",
"6937659201108818891889533980728331394636689918099 5",
"2346163400688357827545954559967898642295645786741 1",
"7297379445563554743001957415367741699994020499899 4",
"6839224443972914426272175211505486215732997486266 4",
"7720871722457646746446585504950815942621654065732 5",
"2849571014476728078068197500593134386186885299922 7",
"1651457838222483124474400252361004538800428957057 5",
"1389247786408261926539493092831106767328385056104 7",
"3411909026225654193551327237427822253336035652600 1",
"5181988532782682353519070469137913545766352207722 9",
"9065755245339664536104617507130000299418224976537 8",
"4398818177575817576691547329920957089391328999018 2",
"6058207518429093154503900538921282783754480683427 4",
"0887982153661592177649487051063875435823974487047 0",
"9113502513103752567914712686753723073170811307274 2",
"8307267973310427295588807815693656586064129096790 0",
"9266060339461476868527944199151589902941967738761 9",
"4428695639326502530432441711794108087706101247063 8",
"5122158565947999825871168537720019016440330308199 2",
"5204925351466014615770749861793750685507032845268 3",
"7050775239207314136343103668345641850066930620573 6",
"8982077485892125042881239620476209127848751982862 2",
"2456780717439579938621246414756581890748398892938 9",
"0405387257092619412909200900955849890768384522548 6",
"8377172591226888243979445102003538241146222532496 2",
"0463392457557302224921732629181941791892054650145 6",
"2195500929283390504473685578955903222418236152656 1",
"4807146977267034428759491285735611726845558313762 6",
"5701163152286637155608646529110874557687162693983 9",
"6965268621808736124384684810104943490794325529495 9",
"6325160975106104206822936391355948745333861591962 9",
"3499579648733291992792851778889369765189231928086 3",
"0894325503659661962481013950905143579873709797102 3",
"6469556602169114946107397304378714216993342898728 0",
"5488751634810127654918579785467746109172416838021 8",
"2442382240220440155673836115638273906340241851438 3",
"7553716822460158240024380995306392778557861668930 1",
"2748129579184756313625455797647322137651541260924 3",
"2044933018278655473429952983562112364311891900867 6",
"3677061754273871244681952951484143880249573012954 7",
"9209289005664171497396770096067930625703140808350 3",
"4814958112292646526157517059810979326113718152255 9",
"0611596502962541178428883651861764598172628754705 8",
"1752438519477484578567778168313603258348377717633 5",
"9179146509493033011680825124924554011037223759078 3",
"3684516686606383771188152419039365179791248839613 7",
"7652571987683959622904718089890707844846177189198 6",
"4789286574282951392045706005361859109795215605215 8",
"9103696823650181481646314071505433723323926112283 8",
"3225697881990279647532295566423275888982784519564 5",
"9920820839003511725625489277171625260535007504831 5",
"1698930336515460033897238666492299125873236436117 4",
"2592582556155755951518749197988850729875916543688 9",
"9144516395075948680815983813883406392458307639334 1",
"7365699429618072480813278616381581651442226513812 1",
"2623229629513931799055727185173553990703982396436 6",
"4800163701511474565254714522486780648018460915420 4",
"0298639488947975281491789960879045251735099057423 8",
"0023107676728164986130437527136314204606330209454 3",
"6038149659885729503698222143941153962352560118794 9",
"6903984979791765537989903236726054939627432569065 8",
"4137441988285323199416592533725190606455350257032 4",
"7675754800805519440483471416431366987142639236783 7",
"3256617913964985024704846877378164630818308651454 5",
"9143722150559339053122892609537294089238806337761 3",
"7141814891759151958610169385694220175289739182805 8",
"5696923423268386307770172578848432210467786017951 2",
"0613514323070254165759045092472806728375363558685 6",
"6923411280588879686184578210501694526750633031717 4",
"4799431994231658234381655685921175667870264263950 1",
"6563193985322329322090540892520145213308630572882 3",
"3832533169921380020075136517685191523495232574357 0",
"1410122100536607823254511566455142166173051380647 6",
"5818147243083294802113471932282687286002243917812 3",
"9197106713839023251502632953675747400891318249648 8",
"9413507468603215887590779579575237709669201513584 2",
"4413016483038064583849116476056414730273792527807 7",
"8553358681362958954197689918556037304536580014138 5",
"4422709075866553163400366041672289760002771306724 1",
"2811873264639505207835166227875984511181175251474 5",
"2705772916218631124704408796202678436381602777370 0",
"4550194307723699102998768828138037952357415236721 6",
"0476690898455450453556099143013063913291525822657 5",
"1400812443664644975591387417404942221742785706120 3",
"1909293900990151879933169907348217644720636511605 3",
"0351996144569828629496706962497160465582258924387 1",
"7036107088900710172233832611921376929976624072191 8",
"3985465779106386931468924774955484102318260729202 2",
"5809806629202490509139539829520312977101778880298 3",
"5194791146992509163753105519984004703051111089110 5",
"7880796702619142508034517950087035996649017026620 7",
"7476238607201894008199372197378412754960851836322 1",
"0650060557541199686289523558506398426019209636937 5",
"7167812542928572723529819281088272070401517492491 5",
"7190137461910549106058492054773376295749315740021 2",
"5289786257826406506950853599802698047380034420736 0",
"0000000000000000000000000000000000000000000000000 0",
"0000000000000000000000000000000000000000000000000 0",
"0000000000000000000000000000000000000000000000000 0",
"0000000000000000000000000000000000000000000000000 0",
"0000000000000000000000000000000000000000000000000 0",
"0000000000000000000000000000000000000000000000000 0",
"0000000000000000000000000000000000000000000000000 0",
"0000000000000000000000000000000000000000000000000 0",
"0000000000000000000000000000000000000000000000000 0",
"0000000000000000000000000000000000000000000000000 0",
"0000000000000000000000000000000000000000000000000 0",
"0000000000000000000000000000000000000000000000000 0",
"0000000000000000000000000000000000000000000000000 0",
"0000000000000000000000000000000000000000000000000 0",
"0000000000000000000000000000000000000000000000000 0",
"0000000000000000000000000000000000000000000000000 0",
"0000000000000000000000000000000000000000000000000 0",
"0000000000000000000000000000000000000000000000000 0",
"0000000000000000000000000000000000000000000000000 0",
"0000000000000000000000000000000000000000000000000 0",
"00000000000000000000",
NULL
};
size_t i = 0;
while(f4096[i] != NULL)
{
printf("%s\n", f4096[i++]);
}
return 0;
}

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Sep 5 '06 #5
ma*********@gmail.com said:
What is the logic to fill the below structure ?
> const char *f4096[] =
{
"3642736389457041931565827470311646920571244923509 8",
"5542995093848478037874935832413874911388522601924 1",
"4089162355975180441627205998905094740308390559314 4",
[...]

Well, I started off by calculating 4096!, and storing that result in a file.
I then wrote the following program, feeding it that file as input:

#include <stdio.h>

int main(void)
{
int i = 0;
int ch = 0;
printf("#include <stdio.h>\n\n");
printf("int main(void)\n{\n");
printf(" const char *f4096[] =\n");
printf(" {\n");
printf(" \"");
while((ch = getc(stdin)) != EOF)
{
if(isdigit(ch))
{
putchar(ch);
++i;
if(i == 50)
{
printf("\",\n \"");
i = 0;
}
}
}
printf("\",\n NULL\n");
printf(" };\n");
printf(" size_t i = 0;\n");
printf(" while(f4096[i] != NULL)\n");
printf(" {\n");
printf(" printf(\"%%s\\n\", f4096[i++]);\n");
printf(" }\n");
printf(" return 0;\n");
printf("}\n");
return 0;
}

....with the result you have already seen.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Sep 5 '06 #6
How did you calculated 4096!. My calc failed and even my program !!
Richard Heathfield wrote:
ma*********@gmail.com said:
What is the logic to fill the below structure ?
const char *f4096[] =
{
"3642736389457041931565827470311646920571244923509 8",
"5542995093848478037874935832413874911388522601924 1",
"4089162355975180441627205998905094740308390559314 4",

[...]

Well, I started off by calculating 4096!, and storing that result in a file.
I then wrote the following program, feeding it that file as input:

#include <stdio.h>

int main(void)
{
int i = 0;
int ch = 0;
printf("#include <stdio.h>\n\n");
printf("int main(void)\n{\n");
printf(" const char *f4096[] =\n");
printf(" {\n");
printf(" \"");
while((ch = getc(stdin)) != EOF)
{
if(isdigit(ch))
{
putchar(ch);
++i;
if(i == 50)
{
printf("\",\n \"");
i = 0;
}
}
}
printf("\",\n NULL\n");
printf(" };\n");
printf(" size_t i = 0;\n");
printf(" while(f4096[i] != NULL)\n");
printf(" {\n");
printf(" printf(\"%%s\\n\", f4096[i++]);\n");
printf(" }\n");
printf(" return 0;\n");
printf("}\n");
return 0;
}

...with the result you have already seen.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Sep 5 '06 #7
ma*********@gmail.com said:
How did you calculated 4096!. My calc failed and even my program !!
Aha! Some evidence that you've had a go yourself. Let's see your program,

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Sep 5 '06 #8
Hi Richard,
I started with the below kind of program which is not working because
of memory overflow.

long long fact(long long n)
{
return n*fact(n-1);
}
int main()
{
printf("%ld",fact(4096));
}

Now I am planning to write the linked list version of addition().
Which inturn will be used by the multiplication(). That inturn by the
fact(). Is these unlimited size data types are already there ?

Richard Heathfield wrote:
ma*********@gmail.com said:
How did you calculated 4096!. My calc failed and even my program !!

Aha! Some evidence that you've had a go yourself. Let's see your program,

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Sep 5 '06 #9
ma*********@gmail.com said:
Hi Richard,
I started with the below kind of program which is not working because
of memory overflow.

long long fact(long long n)
{
return n*fact(n-1);
}
That's a good example of why you should avoid recursive functions until you
know how to make them stop! Better would be:

unsigned long long fact(unsigned int n)
{
unsigned long long f = 1;
while(n)
{
f *= n--;
}
return f;
}

Note that if n is 20, n! is 2432902008176640000 - and that's the highest
factorial value you can *guarantee* to store in an unsigned long long int.

int main()
{
printf("%ld",fact(4096));
Look up the format specifiers for long long int and unsigned long long int
when you get a minute. %ld is for long int, not long long int.
Now I am planning to write the linked list version of addition().
Which inturn will be used by the multiplication(). That inturn by the
fact(). Is these unlimited size data types are already there ?
Well, I think a linked list is probably a bad idea, since it denies you

Personally, I use an array of unsigned char - dynamically allocated - to
store a large number's magnitude, and a separate int value to record
whether it's positive or negative. I store the current magnitude of the
number, too, which I find helpful - and also I track the amount of memory
currently allocated for the array, so that I know when I need to resize.

I use base 256 for my calculations, but you might prefer to keep everything
representable in text format ('0', '1', '2', etc) for your first go.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Sep 5 '06 #10
ma*********@gmail.com wrote:
Hi Richard,
I started with the below kind of program which is not working because
of memory overflow.

long long fact(long long n)
{
return n*fact(n-1);
}
int main()
{
printf("%ld",fact(4096));
}

Now I am planning to write the linked list version of addition().
Which inturn will be used by the multiplication(). That inturn by the
fact(). Is these unlimited size data types are already there ?
A recursive function should have a stop condition ensuring it
terminates.
In this case you want to stop when n reaches 0.
long long fact(long long n)
{
if(n == 0) /* 0! is 1*/
return 1;
else
return n*fact(n-1); /* n! is n*(n -1)! */
}

Rewriting the function to be iterative is likely a better choice.

However, a long long type might not be able to hold a value big enough
to represent the factorial of big numbers. You might resort to doing
all the math yourself (atleast subtraction and multiplication) e.g. in
a similar fashion as you'd do the math on paper. You could use a
postitional numbering system built up from primititive C types, e.g.
an array of ints.
There are libriaries available for various systems doing the math
for you though, generally referred to as bignum libraries.
Sep 5 '06 #11
<ma*********@gmail.comwrote:
>I started with the below kind of program which is not working because
of memory overflow.

long long fact(long long n)
{
return n*fact(n-1);
}
int main()
{
printf("%ld",fact(4096));
}
So what happened when you tried to compute 3! with it?

-- Richard
Sep 5 '06 #12
ma*********@gmail.com wrote:

I started with the below kind of program which is not working because
of memory overflow.

long long fact(long long n)
{
return n*fact(n-1);
}
A good starting test case is to check that your code computes
1! = 1 correctly.
int main()
{
printf("%ld",fact(4096));
}

Now I am planning to write the linked list version of addition().
Which inturn will be used by the multiplication().
And in this case, it doesn't need fully general multiplication either.
That inturn by the
fact().
Is these unlimited size data types are already there ?
There are libraries out there that do unbounded-precision arithmetic,
yes.

But what you can manage with is code that can multiply an
unbounded-precision number by an int. (And something to
print such an int out - which you can hack by working in
base 10, or better 10000.).

--
Chris "seeker" Dollin
Nit-picking is best done among friends.

Sep 5 '06 #13
Chris Dollin said:

<snip>
>
A good starting test case is to check that your code computes
1! = 1 correctly.

<snip>
It does need subtraction, though.

<snip>
There are libraries out there that do unbounded-precision arithmetic,
yes.
No, there aren't, for any reasonable definition of "unbounded".

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Sep 5 '06 #14
ma*********@gmail.com wrote:

What is the logic to fill the below array?

with properly trimmed quotes. See the majority of other posts in the
newsgroup, or:
<http://www.caliburn.nl/topposting.html>

Brian
Sep 5 '06 #15
Richard Heathfield <in*****@invalid.invalidwrites:
Chris Dollin said:
[...]
>There are libraries out there that do unbounded-precision arithmetic,
yes.

No, there aren't, for any reasonable definition of "unbounded".
There are libraries that do arithmetic on quantities whose magnitude
is limited only by available memory.

I won't claim that that's a reasonable definition of "unbounded", but
it's good enough for many applications that don't *really* need
unbounded magnitudes.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Sep 5 '06 #16
Keith Thompson a écrit :
Richard Heathfield <in*****@invalid.invalidwrites:
>>Chris Dollin said:

[...]
>>>There are libraries out there that do unbounded-precision arithmetic,
yes.

No, there aren't, for any reasonable definition of "unbounded".

There are libraries that do arithmetic on quantities whose magnitude
is limited only by available memory.

I won't claim that that's a reasonable definition of "unbounded", but
it's good enough for many applications that don't *really* need
unbounded magnitudes.
Using a relatively small amount of memory for the numbers
in a PC, i.e. 1GB numbers. Supposing 8GB main RAM,
and 16GB swap that would work. You would hold
up to 3 or 4 numbers in core RAM, enough for the
four operations and some intermeidate storage.

We have then numbers of :

1 073 741 824 bytes, i.e. 8 589 934 592 bits.

Dividing by 3 this means (in decimal) numbers of
2 863 311 530 digits, what could be enough for
many applications.

:-)
In a more reasonable realm, 1MB numbers hold 8 388 608
bits or 2 796 202 decimal digits. With a run of the mill
PC with 1GB RAM we can hold several of those numbers
in RAM. No problems!

Not unbounded of course, but the bounds are fairly large
Sep 5 '06 #17
Keith Thompson said:
Richard Heathfield <in*****@invalid.invalidwrites:
>Chris Dollin said:
[...]
>>There are libraries out there that do unbounded-precision arithmetic,
yes.

No, there aren't, for any reasonable definition of "unbounded".

There are libraries that do arithmetic on quantities whose magnitude
is limited only by available memory.
Et viola, monsieur, une bound! :-)
I won't claim that that's a reasonable definition of "unbounded", but
it's good enough for many applications that don't *really* need
unbounded magnitudes.
Sure. Just being my usual nittypicky self.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Sep 5 '06 #18
*** top-posting fixed ***
ma*********@gmail.com wrote:
Richard Heathfield wrote:
>ma*********@gmail.com said:
>>How did you calculated 4096!. My calc failed and even my program !!

Aha! Some evidence that you've had a go yourself. Let's see your

I started with the below kind of program which is not working
because of memory overflow.
.... snip ...
>
Now I am planning to write the linked list version of addition().
Which inturn will be used by the multiplication(). That inturn by
the fact(). Is these unlimited size data types are already there ?
Don't top-post, or you will get no help here. See the links
quoted material.

--
news:news.announce.newusers
http://www.geocities.com/nnqweb/
http://www.catb.org/~esr/faqs/smart-questions.html
http://www.caliburn.nl/topposting.html
http://www.netmeister.org/news/learn2quote.html
Sep 5 '06 #19
ma*********@gmail.com wrote:
>
How to write a program to get the factorial of 4096.
I am working on a Linux m/c.
OT, but you might want to look at the gamma function, depending

--
Thomas M. Sommers -- tm*@nj.net -- AB2SB

Sep 5 '06 #20
In article <44**********************@news.orange.frjacob navia <ja***@jacob.remcomp.frwrites:
....
In a more reasonable realm, 1MB numbers hold 8 388 608
bits or 2 796 202 decimal digits. With a run of the mill
PC with 1GB RAM we can hold several of those numbers
in RAM. No problems!

Not unbounded of course, but the bounds are fairly large
Too small to look for Mersenne primes. (The largest currently known
is 9.152.052 digits.)
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
Sep 6 '06 #21
Dik T. Winter wrote:
Too small to look for Mersenne primes. (The largest currently known
is 9.152.052 digits.)
I have wondered how these are represented, say, by GIMPS.

I kinda-sorta get how the algorithm that GIMPS uses to multiply works,
at least by a casual reading of Knuth vol. 2, multiplication via a DFT.
But I don't yet grasp how an arbitrary precision multiply solves the
problem of representing the numbers (even just the factors) in something
like the Mersenne Prime search.
Sep 6 '06 #22
ma*********@gmail.com wrote:
# Hi
#
# How to write a program to get the factorial of 4096.
# I am working on a Linux m/c.

Use the gamma function from the math library.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
TEMPORARILY CLOSED
BE OPENED AFTER FIRST PERIOD
Sep 6 '06 #23
SM Ryan wrote:
ma*********@gmail.com wrote:
# Hi
#
# How to write a program to get the factorial of 4096.
# I am working on a Linux m/c.

Use the gamma function from the math library.
Even assuming the cephes package and the qfloat version of gamma, it
will not handle an input of 4096:

../qcalc
Steve Moshier's command interpreter V1.3

Functions:
h help hex acos asin atan atantwo cbrt cos cot exp expten log logten
floor acosh asinh atanh cosh sinh tanh fac gamma lgamma jv yv ndtr
ndtri erf erfc pdtr pdtri incbet incbetinv incgam incgaminv ellie ellik
ellpe ellpk in gausshyp confhyp frexp ldexp polylog zeta pow sin sqrt
tan cmp bits digits intcvts double longdouble hexinput remainder dm tm
em take save system rem exit
Variables:
a b c d e f g h i j k l m n o p q r s t u v w x y z pi
Operators:
- , = + - * / ( )
* gamma(4096)
gamma(4096)
qexp overflow error

2.755229909577004387804229723781967737431533629309 4360472858401246561324E5009
*
--
SM Ryan http://www.rawbw.com/~wyrmwif/
TEMPORARILY CLOSED
BE OPENED AFTER FIRST PERIOD
Sep 6 '06 #24
Richard Heathfield wrote:
Chris Dollin said:

<snip>
>>
A good starting test case is to check that your code computes
1! = 1 correctly.

Because I had a sudden attack of non-recall about 0! and went for
speed & safety.
<snip>

It does need subtraction, though.
Subtraction of 1 from a C integer type (in the context of the OPs
post, where 4096 was the number to be banged), yes.
<snip>
>There are libraries out there that do unbounded-precision arithmetic,
yes.

No, there aren't, for any reasonable definition of "unbounded".
Then we differ in our reasonability criteria.

(Specifically, I wanted to avoid saying "infinite precision arithmetic",
and I think it's reasonable for "you don't have enough store" to
stop you working with big numbers: the contrast I was thinking of
was to "you can have big numbers of up to K-for-some-fixed-constant
digits". I suppose you can argue that my "unbounded" is bounded with
K = enough digits to fill available memory.)

--
Chris "seeker" Dollin
"I'm still here and I'm holding the answers" - Karnataka, /Love and Affection/

Sep 6 '06 #25
Chris Dollin said:
Richard Heathfield wrote:
>Chris Dollin said:
<snip>

It does need subtraction, though.

Subtraction of 1 from a C integer type (in the context of the OPs
post, where 4096 was the number to be banged), yes.
In the general case, however, we must be prepared for factorials such as
1000000000000000000000! - so we must be able to subtract 1 from a bignum.
(And yes, I know... "huge" is an utterly inadequate way to describe the
result of 1000000000000000000000! )
><snip>
>>There are libraries out there that do unbounded-precision arithmetic,
yes.

No, there aren't, for any reasonable definition of "unbounded".

Then we differ in our reasonability criteria.

(Specifically, I wanted to avoid saying "infinite precision arithmetic",

<snip>

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Sep 6 '06 #26
Richard Heathfield wrote:
Chris Dollin said:
>Richard Heathfield wrote:
>>Chris Dollin said:

<snip>

It does need subtraction, though.

Subtraction of 1 from a C integer type (in the context of the OPs
post, where 4096 was the number to be banged), yes.

In the general case, however, we must be prepared for factorials such as
1000000000000000000000! - so we must be able to subtract 1 from a bignum.
One step at a time, I thought: but yes, in general.
(And yes, I know... "huge" is an utterly inadequate way to describe the
result of 1000000000000000000000! )
Pah. Your 1000000000000000000000! is a wimp, a wimpish wimp with knobs
taken off, before my mighty 1024!! ! We could just use adjectives with
emphasising markers so perhaps 1000000000000000000000! is huge! or is
that huge!! ? Or maybe huge, Huge, HUge, HUGe, HUGE, huge!, Huge!, ...
>><snip>

There are libraries out there that do unbounded-precision arithmetic,
yes.

No, there aren't, for any reasonable definition of "unbounded".

Then we differ in our reasonability criteria.

(Specifically, I wanted to avoid saying "infinite precision arithmetic",

Better, although couldn't I be unboundedly arbitrary?

--
Chris "hug!" Dollin
The shortcuts are all full of people using them.

Sep 6 '06 #27
Richard Heathfield wrote:
ma*********@gmail.com said:
>What is the logic to fill the below structure ?
>> const char *f4096[] =
{
"3642736389457041931565827470311646920571244923509 8",
"5542995093848478037874935832413874911388522601924 1",
"4089162355975180441627205998905094740308390559314 4",

[...]

Well, I started off by calculating 4096!, and storing that result in
a file. I then wrote the following program, feeding it that file as
input:
<snip>

A fine example of 'I'd rather write programs to write programs than write
programs'.

--
==============
Not a pedant
==============
Sep 6 '06 #28
Chris Dollin wrote:
Richard Heathfield wrote:
>Chris Dollin said:
>>Richard Heathfield wrote:
.... snip ...
>>>>
No, there aren't, for any reasonable definition of "unbounded".

Then we differ in our reasonability criteria.

(Specifically, I wanted to avoid saying "infinite precision
arithmetic",

Better, although couldn't I be unboundedly arbitrary?
How about you being an arbitrary bounder? :-)

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>

Sep 6 '06 #29
CBFalconer wrote:
Chris Dollin wrote:
>Richard Heathfield wrote:
>>Chris Dollin said:
Richard Heathfield wrote:
... snip ...
>>>>>
No, there aren't, for any reasonable definition of "unbounded".

Then we differ in our reasonability criteria.

(Specifically, I wanted to avoid saying "infinite precision
arithmetic",

Better, although couldn't I be unboundedly arbitrary?

How about you being an arbitrary bounder? :-)
I'm in no fit shape to do any kind of bounding. I can
manage a stroll to the station, even a brisk stroll,
but no bounding.

Are we far enough off topic yet?

--
Chris "arbitrarily stopping" Dollin
Nit-picking is best done among friends.

Sep 6 '06 #30
As someone alredy poitned out, you should stick with GMP :

==============
#include <gmp.h>
int main() {

mpz_t i;
mpz_init(i);
mpz_fac_ui(i, 4096);

return gmp_printf("%Zd\n" ,i);
}
==============
ma*********@gmail.com wrote:
Hi

How to write a program to get the factorial of 4096.
I am working on a Linux m/c.

Best Regards,
Subra
Sep 6 '06 #31
dc*****@connx.com wrote:
SM Ryan wrote:
>>ma*********@gmail.com wrote:
#
# How to write a program to get the factorial of 4096.
# I am working on a Linux m/c.

Use the gamma function from the math library.

Even assuming the cephes package and the qfloat version of gamma, it
will not handle an input of 4096:
Then compute the log of the gamma function instead.

--
Thomas M. Sommers -- tm*@nj.net -- AB2SB

Sep 6 '06 #32
dc*****@connx.com wrote:
# SM Ryan wrote:
# ma*********@gmail.com wrote:
# # Hi
# #
# # How to write a program to get the factorial of 4096.
# # I am working on a Linux m/c.
# >
# Use the gamma function from the math library.
#
# Even assuming the cephes package and the qfloat version of gamma, it
# will not handle an input of 4096:

Quality of implementation.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
Raining down sulphur is like an endurance trial, man. Genocide is the
most exhausting activity one can engage in. Next to soccer.
Sep 6 '06 #33
How to write a program to get the factorial of 4096.
I am working on a Linux m/c.
You will need a very large integer type to represent this. This
is commonly done with a "bignum" library as other posters have
mentioned.

For example: 4096! is the product of 4096 numbers:

2048 of them are multiples of 2.
1024 of them are multiples of 4.
512 of them are multiples of 8.
256 of them are multiples of 16.
128 of them are multiples of 32.
64 of them are multiples of 64.
32 of them are multiples of 128.
16 of them are multiples of 256.
8 of them are multiples of 512.
4 of them are multiples of 1024.
2 of them are multiples of 2048.
1 of them is 4096.

so there are 4095 low-order zero bits in the result. And that only
includes the factors of two in the result, ignoring all the other
stuff. You can do a similar analysis of how many factors of 5 there
are, to determine how many trailing decimal zeroes there are in the
result.

Sep 7 '06 #34

After being insulted in another thread ("no one
advocates gets()" indeed!) I see a problem I can solve:
I started with the below kind of program which is not working because
of memory overflow.

long long fact(long long n)
{
return n*fact(n-1);
}
First of all, the necessary datatype in this application isn't "long
long",
or even "long long long", but "long long Long long HUGE HUGE long
Long long VERY_HUGE big big big plump". Isn't all this in your manual?

That doesn't explain your memory overflow. I think I get more than
4096 smallish pushes with Linux, though I seldom try that many
(at least on purpose). I don't know about Windoze(tm):
Call me old-fashioned but I like to run under an Operating System.

Even compilers smart enough to find tail-recursion automatically,
won't find it in your fact(). You can change this to
iteration easily though.

PS: Working with large factorials is common, but don't we usually
use the logarithm of the factorial? You can get this with 4096 adds,
or just use Stirling's approximation.

Hope this helps with your homework,
James Dow Allen

Sep 7 '06 #35
"James Dow Allen" <jd*********@yahoo.comwrites:
>I started with the below kind of program which is not working because
of memory overflow.

long long fact(long long n)
{
return n*fact(n-1);
}

That doesn't explain your memory overflow. I think I get more than
4096 smallish pushes with Linux, though I seldom try that many
(at least on purpose). I don't know about Windoze(tm):
Call me old-fashioned but I like to run under an Operating System.
The OP's function does not limit recursion to 4096 levels.
--
"I don't have C&V for that handy, but I've got Dan Pop."
--E. Gibbons
Sep 7 '06 #36
Richard Heathfield wrote:
>
Look up the format specifiers for long long int and unsigned long long int
when you get a minute. %ld is for long int, not long long int.
What is this 'long long int' of which you speak? My compiler,
in conforming mode, doesn't support it...

Sep 8 '06 #37
Gordon Burditt wrote:
so there are 4095 low-order zero bits in the result. And that only
includes the factors of two in the result, ignoring all the other
stuff. You can do a similar analysis of how many factors of 5 there
are, to determine how many trailing decimal zeroes there are in the
result.
An interesting problem -- what's the last non-zero digit of one
million factorial?

Sep 8 '06 #38
Old Wolf said:
Richard Heathfield wrote:
>>
Look up the format specifiers for long long int and unsigned long long
int when you get a minute. %ld is for long int, not long long int.

What is this 'long long int' of which you speak? My compiler,
in conforming mode, doesn't support it...
Neither does mine. Nevertheless, the OP was using long long, so presumably
he has a C99 compiler. C99 is topical here.

If, however, you are suggesting that the use of long long int renders the
code less portable than it might be, then I agree entirely.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Sep 8 '06 #39
Old Wolf said:
An interesting problem -- what's the last non-zero digit of one
million factorial?
1 (assuming binary notation).

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Sep 8 '06 #40

In article <5M********************@bt.com>, Richard Heathfield <in*****@invalid.invalidwrites:
Old Wolf said:
An interesting problem -- what's the last non-zero digit of one
million factorial?

1 (assuming binary notation).
1 (assuming base-1000000! notation).

(On a more serious note: if we're using base 10, the least-
significant non-zero digit has to be one of {2,4,6,8}, but further
analysis is beyond my skills, at least for casual Usenet speculation.)

--
Michael Wojcik mi************@microfocus.com
Sep 8 '06 #41
Old Wolf wrote:
Richard Heathfield wrote:
>>Look up the format specifiers for long long int and unsigned long long int
when you get a minute. %ld is for long int, not long long int.

What is this 'long long int' of which you speak? My compiler,
in conforming mode, doesn't support it...
Compiler in "conforming mode" ???

Conforming to what?

Standard C has short int, int, long int and long long int.

You are conforming to another, not the current C standard.

P.S.

-std=c99 if you use gcc
Sep 8 '06 #42
jacob navia <ja***@jacob.remcomp.frwrites:
Old Wolf wrote:
>Richard Heathfield wrote:
>>>Look up the format specifiers for long long int and unsigned long long int
when you get a minute. %ld is for long int, not long long int.
What is this 'long long int' of which you speak? My compiler,
in conforming mode, doesn't support it...

Compiler in "conforming mode" ???

Conforming to what?
Conforming to C89/C90, as Richard has made extremely clear many times.
Standard C has short int, int, long int and long long int.

You are conforming to another, not the current C standard.

P.S.

-std=c99 if you use gcc
With "-std=c89", gcc conforms to the C89/C90 (undoubtedly with a few
bugs here and there).

With "-std=c99", gcc does not fully conform to *any* standard.

So "-std=c89" (or "-ansi") is the *only* "conforming mode" available
for gcc, and it will be until gcc fully implements C99.

Many C compilers implement *some* of the new features in C99, but very
few implement all of them, and different compilers implement different
sets of features. The best way to write maximally portable C code is
to limit yourself to C89/C90, while avoiding any conflicts with C99
(e.g., don't use implicit int, and don't use "restrict" as an
identifier). With gcc, "-std=c89", along with some other options,
does a decent job of warning about code that doesn't meet these limits
(it probably won't warn about "restrict", but that's easy enough to
handle manually).

There are probably some C99 features that are supported by almost all
compilers, such as "//" comments. So it's tempting to write code in
the subset of C99 that includes all of C90 plus "//" comments. But
there is no set of options for gcc that will permit "//" features and
still warn about C99 features that are not yet portable.

There is still a real price for using C99 features. If you're willing
to pay that price, that's fine. Richard is not, for perfectly good
reasons that he has explained before.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Sep 8 '06 #43

"James Dow Allen" <jd*********@yahoo.comwrote in message
>
After being insulted in another thread ("no one
advocates gets()" indeed!) I see a problem I can solve:
>I started with the below kind of program which is not working because
of memory overflow.

long long fact(long long n)
{
return n*fact(n-1);
}

First of all, the necessary datatype in this application isn't "long
long",
or even "long long long", but "long long Long long HUGE HUGE long
Long long VERY_HUGE big big big plump". Isn't all this in your manual?

That doesn't explain your memory overflow. I think I get more than
4096 smallish pushes with Linux, though I seldom try that many
(at least on purpose). I don't know about Windoze(tm):
Call me old-fashioned but I like to run under an Operating System.

Even compilers smart enough to find tail-recursion automatically,
won't find it in your fact(). You can change this to
iteration easily though.

PS: Working with large factorials is common, but don't we usually
use the logarithm of the factorial? You can get this with 4096 adds,
or just use Stirling's approximation.

Hope this helps with your homework,
James Dow Allen
Take n to be 4095. Root 2 pi n is going to be 160. n over e is going to
1516. 1.516 exceeds three halves. Three halves excceds one. So the number
we're looking at is bounded below by 160 times quatity one thousand to the
4095. To represent in decimal fashion would therefore require 2+3*4095>12
thousand places. Is bigbum.h any help in working with numbers of this size
in C? EC
Sep 8 '06 #44
Richard Heathfield wrote:
Elijah Cardon said:
>To represent [4096!] in decimal fashion would therefore require
2+3*4095>12 thousand places.

Er, so what? As we've already seen, it is possible to deal with numbers as
large as that in C, if you're prepared or were prepared at some point in
the past to take a little time and effort or to pinch someone else's
library.
Well, this looks like the business part of bignum.h:

#define LITTLENUM_NUMBER_OF_BITS (16)
#define LITTLENUM_SHIFT (1)
#define CHARS_PER_LITTLENUM (1 << LITTLENUM_SHIFT)
#ifndef BITS_PER_CHAR
#define BITS_PER_CHAR (8)
#endif

typedef unsigned short LITTLENUM_TYPE;

/* JF truncated this to get around a problem with GCC */
#define LOG_TO_BASE_2_OF_10 (3.3219280948873623478703194294893901758651)
/* WARNING: I haven't checked that the trailing digits are correct! */

/* lengths are in sizeof(littlenum)s */

int bignum_copy (LITTLENUM_TYPE * in, int in_length,
LITTLENUM_TYPE * out, int out_length);

/* end of bignum.h */
It seems to me that this is going after long numbers as opposed to big
numbers. Long numbers are like pi. Borwein and Borwein have an
excellent book on this that I read maybe a decade ago(_Pi and the AGM_).
So if you have pi to 13000 digits and say, "we're just going to remove
the decimal point", then you'd have a big number, but a big number of no
consequence.

I think the way to go is to change the base and represent with entries
in an array. I've never met an interesting number larger than ten to
the fifty-five. Am I right to think that if you have base ten thousand,
then you could represent it in an array of ints that is of length 15? EC
Sep 10 '06 #45
Elijah Cardon said:
Richard Heathfield wrote:
>Elijah Cardon said:
>>To represent [4096!] in decimal fashion would therefore require
2+3*4095>12 thousand places.

Er, so what? As we've already seen, it is possible to deal with numbers
as large as that in C, if you're prepared or were prepared at some point
in the past to take a little time and effort or to pinch someone else's
library.

Well, this looks like the business part of bignum.h:
<snip>
/* end of bignum.h */
It seems to me that this is going after long numbers as opposed to big
numbers.
"How big do we want?" is a significant question for bignum library authors.
I think the way to go is to change the base and represent with entries
in an array. I've never met an interesting number larger than ten to
the fifty-five.
They happen sometimes, in cryptography.
Am I right to think that if you have base ten thousand,
then you could represent it in an array of ints that is of length 15? EC
Personally, I use base 256, which I can represent in any number of unsigned
chars I like. If I worked to base 65536, I could represent it in any number
of unsigned shorts I like.

But let's take your 10^55. Or, if you prefer, 44!, which is
2,658,271,574,788,448,768,043,625,811,014,615,890, 319,638,528,000,000,000

If you wanted to stay in a 10-based base, though, you could do worse than
base 1000. You'd need an array of 19 ints for numbers of the magnitude you
require. Or perhaps you could use base 1000000 and an array of 10 long
ints. But base 1000 is attractive because printing it is so easy, in
locales where numbers are divided into groups of three for printing:

for(i = highest_index; i 0 && n[i] == 0; i++)
{
continue;
}
while(i 1)
{
printf("%03d%c", n[i], thousands_separator);
flag = 1;
}
printf(flag ? "%03d\n" : "%d\n", n[i]);

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Sep 10 '06 #46
Elijah Cardon wrote:
Take n to be 4095. Root 2 pi n is going to be 160. n over e is going to
1516. 1.516 exceeds three halves. Three halves excceds one. So the number
we're looking at is bounded below by 160 times quatity one thousand to the
4095. To represent in decimal fashion would therefore require 2+3*4095>12
thousand places. Is bigbum.h any help in working with numbers of this size
in C? EC
If there is indeed some library somewhere called
bigbum then I'd love to know more about it.

Sep 10 '06 #47
Spiros Bousbouras wrote:
Elijah Cardon wrote:
>Take n to be 4095. Root 2 pi n is going to be 160. n over e is going to
1516. 1.516 exceeds three halves. Three halves excceds one. So the number
we're looking at is bounded below by 160 times quatity one thousand to the
4095. To represent in decimal fashion would therefore require 2+3*4095>12
thousand places. Is bigbum.h any help in working with numbers of this size
in C? EC

If there is indeed some library somewhere called
bigbum then I'd love to know more about it.
'b' is next to 'n' and I have large fingers and hayfever that
occasionally reduces my vision. You can't see the other newsgroups I
subscribe to, can you? EC
Sep 10 '06 #48
In article <12*************@corp.supernews.comElijah Cardon <in*****@invalid.netwrites:
....
I've never met an interesting number larger than ten to
the fifty-five.
Never met an RSA key?
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
Sep 10 '06 #49

Elijah Cardon wrote:
Richard Heathfield wrote:
Elijah Cardon said:
To represent [4096!] in decimal fashion would therefore require
2+3*4095>12 thousand places.
Er, so what? As we've already seen, it is possible to deal with numbers as
large as that in C, if you're prepared or were prepared at some point in
the past to take a little time and effort or to pinch someone else's
library.

Well, this looks like the business part of bignum.h:

#define LITTLENUM_NUMBER_OF_BITS (16)
#define LITTLENUM_SHIFT (1)
#define CHARS_PER_LITTLENUM (1 << LITTLENUM_SHIFT)
#ifndef BITS_PER_CHAR
#define BITS_PER_CHAR (8)
#endif

typedef unsigned short LITTLENUM_TYPE;

/* JF truncated this to get around a problem with GCC */
#define LOG_TO_BASE_2_OF_10 (3.3219280948873623478703194294893901758651)
/* WARNING: I haven't checked that the trailing digits are correct! */

/* lengths are in sizeof(littlenum)s */

int bignum_copy (LITTLENUM_TYPE * in, int in_length,
LITTLENUM_TYPE * out, int out_length);

/* end of bignum.h */
It seems to me that this is going after long numbers as opposed to big
numbers. Long numbers are like pi. Borwein and Borwein have an
excellent book on this that I read maybe a decade ago(_Pi and the AGM_).
So if you have pi to 13000 digits and say, "we're just going to remove
the decimal point", then you'd have a big number, but a big number of no
consequence.

I think the way to go is to change the base and represent with entries
in an array. I've never met an interesting number larger than ten to
the fifty-five. Am I right to think that if you have base ten thousand,
then you could represent it in an array of ints that is of length 15? EC
I use the GMP library which does arbitrary precision integers as large
as your memory will allow (using base 65536 I believe). I use it to
study the Collatz Conjecture where a lot of stuff is exponential so
big numbers are essential.

For example, the formula for the ith kth Generation Type [1,2]
Mersenne Hailstone is:

a(i,k) = 2**(6*((i - 1)*9**(k - 1) + (9**(k - 1) - 1)/2 + 1) - 1) - 1

for which (1,10) gives you a number over a billion bits. It'll do
paltry calculations like 4096! easily.

There is, however, a limitation: the power function considers
an exponent of 32 bits or more "outrageous", so the above
formula only works up to k=10. You can have bigger numbers,
you just can't get there by that path.

Sep 10 '06 #50

### This discussion thread is closed

Replies have been disabled for this discussion.