#include <stdio.h>
#define MAX_DIGITS 50 // 配列要素の数、桁数に対応
// 各要素に割り当てる桁の最大値(7桁まで)
#define BASE 10000000
// resultの初期化(3^0 = 1を設定)
void initialize(unsigned long result[]) {
result[0] = 1; // 初期値として一番下の桁に1をセット
for (int i = 1; i < MAX_DIGITS; i++) {
result[i] = 0; // 残りの桁をすべて0に初期化
}
}
// 3の累乗を計算し、配列に格納する関数
void power3(unsigned long result[], int n) {
for (int i = 0; i < n; i++) {
unsigned long carry = 0; // 繰り上げ用の変数
for (int j = 0; j < MAX_DIGITS; j++) {
unsigned long temp = result[j] * 3 + carry; // 3倍して繰り上げを加える
result[j] = temp % BASE; // 現在の桁に収まる部分(7桁以内)
carry = temp / BASE; // 8桁目に溢れた部分は繰り上げ用に保持
}
}
}
// 配列の中身を表示する関数
void print_result(unsigned long result[]) {
// 最上位の非0桁を探す
int start = MAX_DIGITS - 1;
while (start > 0 && result[start] == 0) {
start--;
}
// 最上位桁を表示
// 残りの桁を7桁ずつ0埋めで表示
for (int i = start - 1; i >= 0; i--) {
printf("%07lu", result
[i
]); // 7桁の0埋めで表示 }
}
int main() {
unsigned long result[MAX_DIGITS]; // 各要素が7桁まで扱える配列
// 初期値をセット
initialize(result);
// 3の99乗を計算
power3(result, 99);
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNkZWZpbmUgTUFYX0RJR0lUUyA1MCAgLy8g6YWN5YiX6KaB57Sg44Gu5pWw44CB5qGB5pWw44Gr5a++5b+cCgovLyDlkITopoHntKDjgavlibLjgorlvZPjgabjgovmoYHjga7mnIDlpKflgKTvvIg35qGB44G+44Gn77yJCiNkZWZpbmUgQkFTRSAxMDAwMDAwMAoKLy8gcmVzdWx044Gu5Yid5pyf5YyW77yIM14wID0gMeOCkuioreWumu+8iQp2b2lkIGluaXRpYWxpemUodW5zaWduZWQgbG9uZyByZXN1bHRbXSkgewogICAgcmVzdWx0WzBdID0gMTsgIC8vIOWIneacn+WApOOBqOOBl+OBpuS4gOeVquS4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Aoc3RhcnQgPiAwICYmIHJlc3VsdFtzdGFydF0gPT0gMCkgewogICAgICAgIHN0YXJ0LS07CiAgICB9CgogICAgLy8g5pyA5LiK5L2N5qGB44KS6KGo56S6CiAgICBwcmludGYoIiVsdSIsIHJlc3VsdFtzdGFydF0pOwoKICAgIC8vIOaui+OCiuOBruahgeOCkjfmoYHjgZrjgaQw5Z+L44KB44Gn6KGo56S6CiAgICBmb3IgKGludCBpID0gc3RhcnQgLSAxOyBpID49IDA7IGktLSkgewogICAgICAgIHByaW50ZigiJTA3bHUiLCByZXN1bHRbaV0pOyAgLy8gN+ahgeOBrjDln4vjgoHjgafooajnpLoKICAgIH0KICAgIHByaW50ZigiXG4iKTsKfQoKaW50IG1haW4oKSB7CiAgICB1bnNpZ25lZCBsb25nIHJlc3VsdFtNQVhfRElHSVRTXTsgIC8vIOWQhOimgee0oOOBjDfmoYHjgb7jgafmibHjgYjjgovphY3liJcKCiAgICAvLyDliJ3mnJ/lgKTjgpLjgrvjg4Pjg4gKICAgIGluaXRpYWxpemUocmVzdWx0KTsKCiAgICAvLyAz44GuOTnkuZfjgpLoqIjnrpcKICAgIHBvd2VyMyhyZXN1bHQsIDk5KTsKfQ==