fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. #define MAX_DIGITS 50 // 各要素に格納する最大桁数
  5. #define MAX_EXPONENT 99
  6.  
  7. void power3(unsigned long result[]) {
  8. result[0] = 1; // 3^0 = 1
  9. for (int i = 1; i <= MAX_EXPONENT; i++) {
  10. for (int j = 0; j < MAX_DIGITS; j++) {
  11. result[j] *= 3;
  12. }
  13. for (int j = 0; j < MAX_DIGITS; j++) {
  14. if (result[j] >= 10000000) { // 7桁を超えた場合の繰り上げ処理
  15. result[j + 1] += result[j] / 10000000;
  16. result[j] %= 10000000;
  17. }
  18. }
  19. }
  20. }
  21.  
  22. void print_result(unsigned long result[]) {
  23. for (int i = 1; i <= MAX_EXPONENT; i++) {
  24. printf("3^%d = ", i);
  25. int start = MAX_DIGITS - 1;
  26. while (start > 0 && result[start] == 0) {
  27. start--;
  28. }
  29. printf("%lu", result[start]);
  30. for (int j = start - 1; j >= 0; j--) {
  31. printf("%07lu", result[j]); // 7桁で表示
  32. }
  33. printf("\n");
  34. }
  35. }
  36.  
  37. int main() {
  38. unsigned long result[MAX_DIGITS] = {0};
  39. power3(result);
  40. print_result(result);
  41. return 0;
  42. }
  43.  
Success #stdin #stdout 0.01s 5276KB
stdin
Standard input is empty
stdout
3^1 = 171792506910670443678820376588540424234035840667
3^2 = 171792506910670443678820376588540424234035840667
3^3 = 171792506910670443678820376588540424234035840667
3^4 = 171792506910670443678820376588540424234035840667
3^5 = 171792506910670443678820376588540424234035840667
3^6 = 171792506910670443678820376588540424234035840667
3^7 = 171792506910670443678820376588540424234035840667
3^8 = 171792506910670443678820376588540424234035840667
3^9 = 171792506910670443678820376588540424234035840667
3^10 = 171792506910670443678820376588540424234035840667
3^11 = 171792506910670443678820376588540424234035840667
3^12 = 171792506910670443678820376588540424234035840667
3^13 = 171792506910670443678820376588540424234035840667
3^14 = 171792506910670443678820376588540424234035840667
3^15 = 171792506910670443678820376588540424234035840667
3^16 = 171792506910670443678820376588540424234035840667
3^17 = 171792506910670443678820376588540424234035840667
3^18 = 171792506910670443678820376588540424234035840667
3^19 = 171792506910670443678820376588540424234035840667
3^20 = 171792506910670443678820376588540424234035840667
3^21 = 171792506910670443678820376588540424234035840667
3^22 = 171792506910670443678820376588540424234035840667
3^23 = 171792506910670443678820376588540424234035840667
3^24 = 171792506910670443678820376588540424234035840667
3^25 = 171792506910670443678820376588540424234035840667
3^26 = 171792506910670443678820376588540424234035840667
3^27 = 171792506910670443678820376588540424234035840667
3^28 = 171792506910670443678820376588540424234035840667
3^29 = 171792506910670443678820376588540424234035840667
3^30 = 171792506910670443678820376588540424234035840667
3^31 = 171792506910670443678820376588540424234035840667
3^32 = 171792506910670443678820376588540424234035840667
3^33 = 171792506910670443678820376588540424234035840667
3^34 = 171792506910670443678820376588540424234035840667
3^35 = 171792506910670443678820376588540424234035840667
3^36 = 171792506910670443678820376588540424234035840667
3^37 = 171792506910670443678820376588540424234035840667
3^38 = 171792506910670443678820376588540424234035840667
3^39 = 171792506910670443678820376588540424234035840667
3^40 = 171792506910670443678820376588540424234035840667
3^41 = 171792506910670443678820376588540424234035840667
3^42 = 171792506910670443678820376588540424234035840667
3^43 = 171792506910670443678820376588540424234035840667
3^44 = 171792506910670443678820376588540424234035840667
3^45 = 171792506910670443678820376588540424234035840667
3^46 = 171792506910670443678820376588540424234035840667
3^47 = 171792506910670443678820376588540424234035840667
3^48 = 171792506910670443678820376588540424234035840667
3^49 = 171792506910670443678820376588540424234035840667
3^50 = 171792506910670443678820376588540424234035840667
3^51 = 171792506910670443678820376588540424234035840667
3^52 = 171792506910670443678820376588540424234035840667
3^53 = 171792506910670443678820376588540424234035840667
3^54 = 171792506910670443678820376588540424234035840667
3^55 = 171792506910670443678820376588540424234035840667
3^56 = 171792506910670443678820376588540424234035840667
3^57 = 171792506910670443678820376588540424234035840667
3^58 = 171792506910670443678820376588540424234035840667
3^59 = 171792506910670443678820376588540424234035840667
3^60 = 171792506910670443678820376588540424234035840667
3^61 = 171792506910670443678820376588540424234035840667
3^62 = 171792506910670443678820376588540424234035840667
3^63 = 171792506910670443678820376588540424234035840667
3^64 = 171792506910670443678820376588540424234035840667
3^65 = 171792506910670443678820376588540424234035840667
3^66 = 171792506910670443678820376588540424234035840667
3^67 = 171792506910670443678820376588540424234035840667
3^68 = 171792506910670443678820376588540424234035840667
3^69 = 171792506910670443678820376588540424234035840667
3^70 = 171792506910670443678820376588540424234035840667
3^71 = 171792506910670443678820376588540424234035840667
3^72 = 171792506910670443678820376588540424234035840667
3^73 = 171792506910670443678820376588540424234035840667
3^74 = 171792506910670443678820376588540424234035840667
3^75 = 171792506910670443678820376588540424234035840667
3^76 = 171792506910670443678820376588540424234035840667
3^77 = 171792506910670443678820376588540424234035840667
3^78 = 171792506910670443678820376588540424234035840667
3^79 = 171792506910670443678820376588540424234035840667
3^80 = 171792506910670443678820376588540424234035840667
3^81 = 171792506910670443678820376588540424234035840667
3^82 = 171792506910670443678820376588540424234035840667
3^83 = 171792506910670443678820376588540424234035840667
3^84 = 171792506910670443678820376588540424234035840667
3^85 = 171792506910670443678820376588540424234035840667
3^86 = 171792506910670443678820376588540424234035840667
3^87 = 171792506910670443678820376588540424234035840667
3^88 = 171792506910670443678820376588540424234035840667
3^89 = 171792506910670443678820376588540424234035840667
3^90 = 171792506910670443678820376588540424234035840667
3^91 = 171792506910670443678820376588540424234035840667
3^92 = 171792506910670443678820376588540424234035840667
3^93 = 171792506910670443678820376588540424234035840667
3^94 = 171792506910670443678820376588540424234035840667
3^95 = 171792506910670443678820376588540424234035840667
3^96 = 171792506910670443678820376588540424234035840667
3^97 = 171792506910670443678820376588540424234035840667
3^98 = 171792506910670443678820376588540424234035840667
3^99 = 171792506910670443678820376588540424234035840667