#include <stdio.h>
#define DIGITS 50 // 必要な桁数 (仮に50桁分の計算を行う)
#define BASE 10000000 // 7桁で分割する
void power3(unsigned long result[]);
void print_result(unsigned long result[]);
int main() {
unsigned long result[DIGITS] = {0}; // 各要素に初期値を設定
result[0] = 1; // 3の0乗 = 1 を初期値として設定
for (int i = 1; i <= 99; i++) {
power3(result); // 3倍を繰り返して累乗計算
print_result(result); // 計算結果を表示
}
return 0;
}
// 3の累乗を計算してresultに格納する関数
void power3(unsigned long result[]) {
unsigned long carry = 0; // 繰り上がりを保持する変数
for (int i = 0; i < DIGITS; i++) {
unsigned long temp = result[i] * 3 + carry;
result[i] = temp % BASE; // 現在の桁に7桁以内の値を格納
carry = temp / BASE; // 繰り上がり分を次の桁に回す
}
}
// resultの中身を表示する関数
void print_result(unsigned long result[]) {
int start = DIGITS - 1;
// 上位のゼロをスキップする
while (start > 0 && result[start] == 0) {
start--;
}
// 最上位の桁を表示(ゼロ埋めしない)
// 残りの桁をゼロ埋めして表示
for (int i = start - 1; i >= 0; i--) {
printf(" %07lu", result
[i
]); // 7桁で表示 }
}
I2luY2x1ZGUgPHN0ZGlvLmg+CgojZGVmaW5lIERJR0lUUyA1MCAgLy8g5b+F6KaB44Gq5qGB5pWwICjku67jgas1MOahgeWIhuOBruioiOeul+OCkuihjOOBhikKI2RlZmluZSBCQVNFIDEwMDAwMDAwICAvLyA35qGB44Gn5YiG5Ymy44GZ44KLCgp2b2lkIHBvd2VyMyh1bnNpZ25lZCBsb25nIHJlc3VsdFtdKTsKdm9pZCBwcmludF9yZXN1bHQodW5zaWduZWQgbG9uZyByZXN1bHRbXSk7CgppbnQgbWFpbigpIHsKICAgIHVuc2lnbmVkIGxvbmcgcmVzdWx0W0RJR0lUU10gPSB7MH07ICAvLyDlkITopoHntKDjgavliJ3mnJ/lgKTjgpLoqK3lrpoKICAgIHJlc3VsdFswXSA9IDE7ICAvLyAz44GuMOS5lyA9IDEg44KS5Yid5pyf5YCk44Go44GX44Gm6Kit5a6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