fork download
  1. #include <stdio.h>
  2.  
  3. void power3(unsigned long result[]) {
  4. unsigned long a = 0;
  5. for (int i = 0; i < 48; i++) {
  6. result[i] = result[i] * 3 + a;
  7. a = result[i] / 10000000;
  8. result[i] %= 10000000;
  9. }
  10. }
  11.  
  12. void print_result(unsigned long result[]) {
  13. int a = 0;
  14. for (int i = 47; i >= 0; i--) {
  15. if (a) {
  16. printf("%lu", result[i]);
  17. } else if (result[i] != 0) {
  18. printf("%lu", result[i]);
  19. a = 1;
  20. }
  21. }
  22. if (!a) {
  23. printf("0");
  24. }
  25. printf("\n");
  26. }
  27.  
  28. int main() {
  29. unsigned long result[48] = {0};
  30. result[0] = 1;
  31.  
  32.  
  33. for (int n = 1; n <= 99; n++) {
  34. power3(result);
  35. printf("n = %d: ", n);
  36. print_result(result);
  37. }
  38.  
  39. return 0;
  40. }
  41.  
Success #stdin #stdout 0s 5280KB
stdin
Standard input is empty
stdout
n = 1: 3
n = 2: 9
n = 3: 27
n = 4: 81
n = 5: 243
n = 6: 729
n = 7: 2187
n = 8: 6561
n = 9: 19683
n = 10: 59049
n = 11: 177147
n = 12: 531441
n = 13: 1594323
n = 14: 4782969
n = 15: 14348907
n = 16: 43046721
n = 17: 129140163
n = 18: 387420489
n = 19: 1162261467
n = 20: 3486784401
n = 21: 1046353203
n = 22: 31381059609
n = 23: 94143178827
n = 24: 282429536481
n = 25: 847288609443
n = 26: 2541865828329
n = 27: 7625597484987
n = 28: 22876792454961
n = 29: 68630377364883
n = 30: 25891132094649
n = 31: 617673396283947
n = 32: 1853020188851841
n = 33: 5559060566555523
n = 34: 16677181699666569
n = 35: 50031545098999707
n = 36: 150094635296999121
n = 37: 45028390589997363
n = 38: 1350851717672992089
n = 39: 4052555153018976267
n = 40: 12157665459056928801
n = 41: 3647299637717786403
n = 42: 109418989131512359209
n = 43: 328256967394537077627
n = 44: 98477092183611232881
n = 45: 295431276550833698643
n = 46: 8862938119652501095929
n = 47: 26588814358957503287787
n = 48: 79766443076872509863361
n = 49: 239299329230617529590083
n = 50: 717897987691852588770249
n = 51: 2153693963075557766310747
n = 52: 646181889226673298932241
n = 53: 19383245667680019896796723
n = 54: 5814973700304005969390169
n = 55: 174449211009120179071170507
n = 56: 523347633027360537213511521
n = 57: 157004289908208161164534563
n = 58: 4710128697246244834921603689
n = 59: 1413038691738734504764811067
n = 60: 4239115827521623514294433201
n = 61: 127173474825648610542883299603
n = 62: 381520424476945831628649898809
n = 63: 1144561273430837494885949696427
n = 64: 3433683820292512484657849089281
n = 65: 10301051460877537453973547267843
n = 66: 30903154382632612361920641803529
n = 67: 92709463147897837085761925410587
n = 68: 278128389443693511257285776231761
n = 69: 83438516833180533771857328695283
n = 70: 2503155504993241601315571986085849
n = 71: 7509466514979724803946715958257547
n = 72: 22528399544939174411840147874772641
n = 73: 67585198634817523235520443624317923
n = 74: 22755595904452569706561330872953769
n = 75: 68266787713357709119683992618861307
n = 76: 1824800363140073127359051977856583921
n = 77: 5474401089420219382077155933569751763
n = 78: 16423203268260658146231467800709255289
n = 79: 4926960980478197443869443402127765867
n = 80: 14788829414345923316083210206383297601
n = 81: 443426488243037769948249630619149892803
n = 82: 1330279464729113309844748891857449678409
n = 83: 3990838394187339929534246675572349035227
n = 84: 11972515182562019788602740026717047105681
n = 85: 35917545547686059365808220080151141317043
n = 86: 107752636643058178097424660240453423951129
n = 87: 32325799929174534292273980721360271853387
n = 88: 969773729787523602876821942164080815560161
n = 89: 290932118936257808630465826492242446680483
n = 90: 87279635680877124258913974794767273441449
n = 91: 261838907426313727767419243843018202124347
n = 92: 7855167211278941183302257731529054606373041
n = 93: 235655016338368235499067731945871638181119123
n = 94: 706965049015104706497203195837614914543357369
n = 95: 21208951470453141194916095875128447436372107
n = 96: 636268544113594235847482876253853423089216321
n = 97: 1908856323478270754244862876156269267648963
n = 98: 5726416897022348122627345886284688078011946889
n = 99: 171792506910670443678820376588540424234035840667