fork download
  1. #include <stdio.h>
  2.  
  3. #define MAX_DIGITS 100
  4.  
  5. void power3(unsigned long result[]);
  6. void print_result(unsigned long result[]);
  7. void power3(unsigned long result[]) {
  8. unsigned long carry = 0;
  9. for (int i = 0; i < MAX_DIGITS; i++) {
  10. unsigned long temp = result[i] * 3 + carry;
  11. result[i] = temp % 10000000;
  12. carry = temp / 10000000;
  13. }
  14. }
  15. void print_result(unsigned long result[]) {
  16. int started = 0;
  17. for (int i = MAX_DIGITS - 1; i >= 0; i--) {
  18. if (result[i] != 0) {
  19. if (started)
  20. printf("%07lu", result[i]);
  21. else {
  22. printf("%lu", result[i]);
  23. started = 1;
  24. }
  25. } else if (started) {
  26. printf("%07lu", result[i]);
  27. }
  28. }
  29. printf("\n");
  30. }
  31. int main() {
  32. unsigned long result[MAX_DIGITS] = {0};
  33. result[0] = 1;
  34.  
  35. for (int i = 1; i <= 99; i++) {
  36. power3(result);
  37. printf("3^%d = ", i);
  38. print_result(result);
  39. }
  40.  
  41. return 0;
  42. }
Success #stdin #stdout 0s 5268KB
stdin
Standard input is empty
stdout
3^1 = 3
3^2 = 9
3^3 = 27
3^4 = 81
3^5 = 243
3^6 = 729
3^7 = 2187
3^8 = 6561
3^9 = 19683
3^10 = 59049
3^11 = 177147
3^12 = 531441
3^13 = 1594323
3^14 = 4782969
3^15 = 14348907
3^16 = 43046721
3^17 = 129140163
3^18 = 387420489
3^19 = 1162261467
3^20 = 3486784401
3^21 = 10460353203
3^22 = 31381059609
3^23 = 94143178827
3^24 = 282429536481
3^25 = 847288609443
3^26 = 2541865828329
3^27 = 7625597484987
3^28 = 22876792454961
3^29 = 68630377364883
3^30 = 205891132094649
3^31 = 617673396283947
3^32 = 1853020188851841
3^33 = 5559060566555523
3^34 = 16677181699666569
3^35 = 50031545098999707
3^36 = 150094635296999121
3^37 = 450283905890997363
3^38 = 1350851717672992089
3^39 = 4052555153018976267
3^40 = 12157665459056928801
3^41 = 36472996377170786403
3^42 = 109418989131512359209
3^43 = 328256967394537077627
3^44 = 984770902183611232881
3^45 = 2954312706550833698643
3^46 = 8862938119652501095929
3^47 = 26588814358957503287787
3^48 = 79766443076872509863361
3^49 = 239299329230617529590083
3^50 = 717897987691852588770249
3^51 = 2153693963075557766310747
3^52 = 6461081889226673298932241
3^53 = 19383245667680019896796723
3^54 = 58149737003040059690390169
3^55 = 174449211009120179071170507
3^56 = 523347633027360537213511521
3^57 = 1570042899082081611640534563
3^58 = 4710128697246244834921603689
3^59 = 14130386091738734504764811067
3^60 = 42391158275216203514294433201
3^61 = 127173474825648610542883299603
3^62 = 381520424476945831628649898809
3^63 = 1144561273430837494885949696427
3^64 = 3433683820292512484657849089281
3^65 = 10301051460877537453973547267843
3^66 = 30903154382632612361920641803529
3^67 = 92709463147897837085761925410587
3^68 = 278128389443693511257285776231761
3^69 = 834385168331080533771857328695283
3^70 = 2503155504993241601315571986085849
3^71 = 7509466514979724803946715958257547
3^72 = 22528399544939174411840147874772641
3^73 = 67585198634817523235520443624317923
3^74 = 202755595904452569706561330872953769
3^75 = 608266787713357709119683992618861307
3^76 = 1824800363140073127359051977856583921
3^77 = 5474401089420219382077155933569751763
3^78 = 16423203268260658146231467800709255289
3^79 = 49269609804781974438694403402127765867
3^80 = 147808829414345923316083210206383297601
3^81 = 443426488243037769948249630619149892803
3^82 = 1330279464729113309844748891857449678409
3^83 = 3990838394187339929534246675572349035227
3^84 = 11972515182562019788602740026717047105681
3^85 = 35917545547686059365808220080151141317043
3^86 = 107752636643058178097424660240453423951129
3^87 = 323257909929174534292273980721360271853387
3^88 = 969773729787523602876821942164080815560161
3^89 = 2909321189362570808630465826492242446680483
3^90 = 8727963568087712425891397479476727340041449
3^91 = 26183890704263137277674192438430182020124347
3^92 = 78551672112789411833022577315290546060373041
3^93 = 235655016338368235499067731945871638181119123
3^94 = 706965049015104706497203195837614914543357369
3^95 = 2120895147045314119491609587512844743630072107
3^96 = 6362685441135942358474828762538534230890216321
3^97 = 19088056323407827075424486287615602692670648963
3^98 = 57264168970223481226273458862846808078011946889
3^99 = 171792506910670443678820376588540424234035840667