fork download
  1. #include <stdio.h>
  2.  
  3. void power3(unsigned long result[]);
  4. void print_result(unsigned long result[]);
  5.  
  6. int main() {
  7. unsigned long result[7];
  8. for (int i = 0; i < 7; i++) {
  9. result[i] = 0;
  10. }
  11. result[0] = 1;
  12. for (int i = 1; i <= 99; i++) {
  13. printf("3^%d: ", i);
  14. print_result(result);
  15. power3(result);
  16. }
  17.  
  18. return 0;
  19. }
  20.  
  21. void power3(unsigned long result[]) {
  22. unsigned long carry = 0;
  23. for (int i = 0; i < 7; i++) {
  24. unsigned long product = result[i] * 3 + carry;
  25. result[i] = product % 10000000;
  26. carry = product / 10000000;
  27. }
  28. }
  29.  
  30. void print_result(unsigned long result[]) {
  31. int i;
  32. for (i = 6; i >= 0 && result[i] == 0; i--) {
  33. }
  34.  
  35. for (; i >= 0; i--) {
  36. printf("%07lu", result[i]);
  37. }
  38.  
  39. printf("\n");
  40. }
  41.  
Success #stdin #stdout 0s 5484KB
stdin
Standard input is empty
stdout
3^1: 0000001
3^2: 0000003
3^3: 0000009
3^4: 0000027
3^5: 0000081
3^6: 0000243
3^7: 0000729
3^8: 0002187
3^9: 0006561
3^10: 0019683
3^11: 0059049
3^12: 0177147
3^13: 0531441
3^14: 1594323
3^15: 4782969
3^16: 00000014348907
3^17: 00000043046721
3^18: 00000129140163
3^19: 00000387420489
3^20: 00001162261467
3^21: 00003486784401
3^22: 00010460353203
3^23: 00031381059609
3^24: 00094143178827
3^25: 00282429536481
3^26: 00847288609443
3^27: 02541865828329
3^28: 07625597484987
3^29: 22876792454961
3^30: 68630377364883
3^31: 000000205891132094649
3^32: 000000617673396283947
3^33: 000001853020188851841
3^34: 000005559060566555523
3^35: 000016677181699666569
3^36: 000050031545098999707
3^37: 000150094635296999121
3^38: 000450283905890997363
3^39: 001350851717672992089
3^40: 004052555153018976267
3^41: 012157665459056928801
3^42: 036472996377170786403
3^43: 109418989131512359209
3^44: 328256967394537077627
3^45: 984770902183611232881
3^46: 0000002954312706550833698643
3^47: 0000008862938119652501095929
3^48: 0000026588814358957503287787
3^49: 0000079766443076872509863361
3^50: 0000239299329230617529590083
3^51: 0000717897987691852588770249
3^52: 0002153693963075557766310747
3^53: 0006461081889226673298932241
3^54: 0019383245667680019896796723
3^55: 0058149737003040059690390169
3^56: 0174449211009120179071170507
3^57: 0523347633027360537213511521
3^58: 1570042899082081611640534563
3^59: 4710128697246244834921603689
3^60: 00000014130386091738734504764811067
3^61: 00000042391158275216203514294433201
3^62: 00000127173474825648610542883299603
3^63: 00000381520424476945831628649898809
3^64: 00001144561273430837494885949696427
3^65: 00003433683820292512484657849089281
3^66: 00010301051460877537453973547267843
3^67: 00030903154382632612361920641803529
3^68: 00092709463147897837085761925410587
3^69: 00278128389443693511257285776231761
3^70: 00834385168331080533771857328695283
3^71: 02503155504993241601315571986085849
3^72: 07509466514979724803946715958257547
3^73: 22528399544939174411840147874772641
3^74: 67585198634817523235520443624317923
3^75: 000000202755595904452569706561330872953769
3^76: 000000608266787713357709119683992618861307
3^77: 000001824800363140073127359051977856583921
3^78: 000005474401089420219382077155933569751763
3^79: 000016423203268260658146231467800709255289
3^80: 000049269609804781974438694403402127765867
3^81: 000147808829414345923316083210206383297601
3^82: 000443426488243037769948249630619149892803
3^83: 001330279464729113309844748891857449678409
3^84: 003990838394187339929534246675572349035227
3^85: 011972515182562019788602740026717047105681
3^86: 035917545547686059365808220080151141317043
3^87: 107752636643058178097424660240453423951129
3^88: 323257909929174534292273980721360271853387
3^89: 969773729787523602876821942164080815560161
3^90: 0000002909321189362570808630465826492242446680483
3^91: 0000008727963568087712425891397479476727340041449
3^92: 0000026183890704263137277674192438430182020124347
3^93: 0000078551672112789411833022577315290546060373041
3^94: 0000235655016338368235499067731945871638181119123
3^95: 0000706965049015104706497203195837614914543357369
3^96: 0002120895147045314119491609587512844743630072107
3^97: 0006362685441135942358474828762538534230890216321
3^98: 0019088056323407827075424486287615602692670648963
3^99: 0057264168970223481226273458862846808078011946889