#include <stdio.h>
#include <string.h>
#define MAX_DIGITS 100 // 最大桁数
// 関数のプロトタイプ宣言
void power3(unsigned long result[], int *numDigits);
void print_result(unsigned long result[], int numDigits);
int main() {
// 結果を格納する配列を初期化します。ここでは100桁で設定します。
unsigned long result[MAX_DIGITS];
int numDigits = 1; // 現在の桁数
// 初期値を設定します(3の0乗は1です)。
memset(result
, 0, sizeof(result
)); result[0] = 1;
// 1乗から99乗までの計算を行います。
for (int n = 1; n <= 99; n++) {
// 3の累乗計算を行う関数を呼び出します。
power3(result, &numDigits);
// 結果を表示します。
print_result(result, numDigits);
}
return 0;
}
// 3の累乗計算を行う関数
void power3(unsigned long result[], int *numDigits) {
unsigned long carry = 0;
for (int i = 0; i < *numDigits; i++) {
unsigned long temp = result[i] * 3 + carry;
result[i] = temp % 10000000;
carry = temp / 10000000;
}
// 繰り上げがある場合、新しい桁を追加します。
while (carry > 0) {
result[*numDigits] = carry % 10000000;
carry /= 10000000;
(*numDigits)++;
}
}
// 結果を指定された形式で表示する関数
void print_result(unsigned long result[], int numDigits) {
// 最上位桁から最下位桁までループします。
printf("%lu", result
[numDigits
- 1]); // 最上位桁
// 残りの桁を7桁ごとに区切って表示
for (int i = numDigits - 2; i >= 0; i--) {
}
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdHJpbmcuaD4KCiNkZWZpbmUgTUFYX0RJR0lUUyAxMDAgLy8g5pyA5aSn5qGB5pWwCgovLyDplqLmlbDjga7jg5fjg63jg4jjgr/jgqTjg5flrqPoqIAKdm9pZCBwb3dlcjModW5zaWduZWQgbG9uZyByZXN1bHRbXSwgaW50ICpudW1EaWdpdHMpOwp2b2lkIHByaW50X3Jlc3VsdCh1bnNpZ25lZCBsb25nIHJlc3VsdFtdLCBpbnQgbnVtRGlnaXRzKTsKCmludCBtYWluKCkgewogICAgLy8g57WQ5p6c44KS5qC857SN44GZ44KL6YWN5YiX44KS5Yid5pyf5YyW44GX44G+44GZ44CC44GT44GT44Gn44GvMTAw5qGB44Gn6Kit5a6a44GX44G+44GZ44CCCiAgICB1bnNpZ25lZCBsb25nIHJlc3VsdFtNQVhfRElHSVRTXTsKICAgIGludCBudW1EaWdpdHMgPSAxOyAvLyDnj77lnKjjga7moYHmlbAKCiAgICAvLyDliJ3mnJ/lgKTjgpLoqK3lrprjgZfjgb7jgZnvvIgz44GuMOS5l+OBrzHjgafjgZnvvInjgIIKICAgIG1lbXNldChyZXN1bHQsIDAsIHNpemVvZihyZXN1bHQpKTsKICAgIHJlc3VsdFswXSA9IDE7CgogICAgLy8gMeS5l+OBi+OCiTk55LmX44G+44Gn44Gu6KiI566X44KS6KGM44GE44G+44GZ44CCCiAgICBmb3IgKGludCBuID0gMTsgbiA8PSA5OTsgbisrKSB7CiAgICAgICAgLy8gM+OBrue0r+S5l+ioiOeul+OCkuihjOOBhumWouaVsOOCkuWRvOOBs+WHuuOBl+OBvuOBmeOAggogICAgICAgIHBvd2VyMyhyZXN1bHQsICZudW1EaWdpdHMpOwoKICAgICAgICAvLyDntZDmnpzjgpLooajnpLrjgZfjgb7jgZnjgIIKICAgICAgICBwcmludGYoIm49JTJkOiAiLCBuKTsKICAgICAgICBwcmludF9yZXN1bHQocmVzdWx0LCBudW1EaWdpdHMpOwogICAgICAgIHByaW50ZigiXG4iKTsKICAgIH0KCiAgICByZXR1cm4gMDsKfQoKLy8gM+OBrue0r+S5l+ioiOeul+OCkuihjOOBhumWouaVsAp2b2lkIHBvd2VyMyh1bnNpZ25lZCBsb25nIHJlc3VsdFtdLCBpbnQgKm51bURpZ2l0cykgewogICAgdW5zaWduZWQgbG9uZyBjYXJyeSA9IDA7CgogICAgZm9yIChpbnQgaSA9IDA7IGkgPCAqbnVtRGlnaXRzOyBpKyspIHsKICAgICAgICB1bnNpZ25lZCBsb25nIHRlbXAgPSByZXN1bHRbaV0gKiAzICsgY2Fycnk7CiAgICAgICAgcmVzdWx0W2ldID0gdGVtcCAlIDEwMDAwMDAwOwogICAgICAgIGNhcn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