fork download
  1. #include <stdio.h>
  2.  
  3. void power3(unsigned long result[]);
  4. void print_result(unsigned long result[]);
  5.  
  6. int main(void) {
  7. unsigned long result[8] = {0}; // 64ビットの数値を格納するための配列
  8. power3(result);
  9. return 0;
  10. }
  11.  
  12. void power3(unsigned long result[]) {
  13. for (int i = 1; i <= 99; i++) {
  14. unsigned long long a = 1; // 3の累乗を計算するための変数
  15.  
  16. // 3のi乗を計算
  17. for (int j = 0; j < i; j++) {
  18. a *= 3;
  19. }
  20.  
  21. // 結果を8桁ごとに分けて格納
  22. for (int b = 0; b < 8; b++) {
  23. result[b] = 0; // 初期化
  24. }
  25.  
  26. for (int c = 0; a > 0 && c < 8; c++) {
  27. result[c] = a % 100000000; // 下8桁を取り出す
  28. a /= 100000000; // 次の8桁に移動
  29. }
  30.  
  31. // 結果を表示
  32. printf("n=%d: 3^%d = ", i, i);
  33. print_result(result); // 結果を表示
  34. }
  35. }
  36.  
  37. void print_result(unsigned long result[]) {
  38. // 最上位のゼロを非表示にするためのフラグ
  39. int leading_zero = 1;
  40.  
  41. // 逆順で表示(上位桁から)
  42. for (int i = 7; i >= 0; i--) {
  43. if (result[i] != 0) {
  44. leading_zero = 0; // 最上位のゼロでなくなる
  45. }
  46. if (!leading_zero) {
  47. printf("%08lu", result[i]); // 8桁のゼロ埋めで表示
  48. }
  49. }
  50.  
  51. // もし全てゼロなら
  52. if (leading_zero) {
  53. printf("0");
  54. }
  55.  
  56. printf("\n");
  57. }
  58.  
Success #stdin #stdout 0s 5284KB
stdin
Standard input is empty
stdout
n=1: 3^1 = 00000003
n=2: 3^2 = 00000009
n=3: 3^3 = 00000027
n=4: 3^4 = 00000081
n=5: 3^5 = 00000243
n=6: 3^6 = 00000729
n=7: 3^7 = 00002187
n=8: 3^8 = 00006561
n=9: 3^9 = 00019683
n=10: 3^10 = 00059049
n=11: 3^11 = 00177147
n=12: 3^12 = 00531441
n=13: 3^13 = 01594323
n=14: 3^14 = 04782969
n=15: 3^15 = 14348907
n=16: 3^16 = 43046721
n=17: 3^17 = 0000000129140163
n=18: 3^18 = 0000000387420489
n=19: 3^19 = 0000001162261467
n=20: 3^20 = 0000003486784401
n=21: 3^21 = 0000010460353203
n=22: 3^22 = 0000031381059609
n=23: 3^23 = 0000094143178827
n=24: 3^24 = 0000282429536481
n=25: 3^25 = 0000847288609443
n=26: 3^26 = 0002541865828329
n=27: 3^27 = 0007625597484987
n=28: 3^28 = 0022876792454961
n=29: 3^29 = 0068630377364883
n=30: 3^30 = 0205891132094649
n=31: 3^31 = 0617673396283947
n=32: 3^32 = 1853020188851841
n=33: 3^33 = 5559060566555523
n=34: 3^34 = 000000016677181699666569
n=35: 3^35 = 000000050031545098999707
n=36: 3^36 = 000000150094635296999121
n=37: 3^37 = 000000450283905890997363
n=38: 3^38 = 000001350851717672992089
n=39: 3^39 = 000004052555153018976267
n=40: 3^40 = 000012157665459056928801
n=41: 3^41 = 000018026252303461234787
n=42: 3^42 = 000017185268762964601129
n=43: 3^43 = 000014662318141474700155
n=44: 3^44 = 000007093466277004997233
n=45: 3^45 = 000002833654757305440083
n=46: 3^46 = 000008500964271916320249
n=47: 3^47 = 000007056148742039409131
n=48: 3^48 = 000002721702152408675777
n=49: 3^49 = 000008165106457226027331
n=50: 3^50 = 000006048575297968530377
n=51: 3^51 = 000018145725893905591131
n=52: 3^52 = 000017543689534297670161
n=53: 3^53 = 000015737580455473907251
n=54: 3^54 = 000010319253219002618521
n=55: 3^55 = 000012511015583298303947
n=56: 3^56 = 000000639558602475808609
n=57: 3^57 = 000001918675807427425827
n=58: 3^58 = 000005756027422282277481
n=59: 3^59 = 000017268082266846832443
n=60: 3^60 = 000014910758653121394097
n=61: 3^61 = 000007838787811945079059
n=62: 3^62 = 000005069619362125685561
n=63: 3^63 = 000015208858086377056683
n=64: 3^64 = 000008733086111712066817
n=65: 3^65 = 000007752514261426648835
n=66: 3^66 = 000004810798710570394889
n=67: 3^67 = 000014432396131711184667
n=68: 3^68 = 000006403700247714450769
n=69: 3^69 = 000000764356669433800691
n=70: 3^70 = 000002293070008301402073
n=71: 3^71 = 000006879210024904206219
n=72: 3^72 = 000002190886001003067041
n=73: 3^73 = 000006572658003009201123
n=74: 3^74 = 000001271229935318051753
n=75: 3^75 = 000003813689805954155259
n=76: 3^76 = 000011441069417862465777
n=77: 3^77 = 000015876464179877845715
n=78: 3^78 = 000010735904392214433913
n=79: 3^79 = 000013760969102933750123
n=80: 3^80 = 000004389419161382147137
n=81: 3^81 = 000013168257484146441411
n=82: 3^82 = 000002611284305020221001
n=83: 3^83 = 000007833852915060663003
n=84: 3^84 = 000005054814671472437393
n=85: 3^85 = 000015164444014417312179
n=86: 3^86 = 000008599843895832833305
n=87: 3^87 = 000007352787613788948299
n=88: 3^88 = 000003611618767657293281
n=89: 3^89 = 000010834856302971879843
n=90: 3^90 = 000014057824835206087913
n=91: 3^91 = 000005279986358199160507
n=92: 3^92 = 000015839959074597481521
n=93: 3^93 = 000010626389076373341331
n=94: 3^94 = 000013432423155410472377
n=95: 3^95 = 000003403781318812313899
n=96: 3^96 = 000010211343956436941697
n=97: 3^97 = 000012187287795601273475
n=98: 3^98 = 000018115119313094268809
n=99: 3^99 = 000017451869791863703195