#include <stdio.h>
#define MAX_DIGITS 8 // 配列の要素あたりの最大桁数
#define MAX_ELEMENTS 8 // 配列の要素数
#define BASE 10000000 // 10^7, 7桁分の値を表すための基数
// 結果を表示する関数
void print_result(unsigned long result[]) {
int i, started = 0;
for (i = MAX_ELEMENTS - 1; i >= 0; i--) {
if (started || result[i] != 0) {
if (started)
printf("%07lu", result
[i
]); // 7桁の0埋め出力 else
printf("%lu", result
[i
]); // 先頭の要素は0埋めしない started = 1;
}
}
if (!started)
}
int main() {
unsigned long result[MAX_ELEMENTS] = {0}; // 結果を格納する配列
result[0] = 1; // 初期値1
for (int n = 0; n < 30; n++) { // 繰り返し回数を30回と仮定
// 各要素を3倍にする
for (int i = 0; i < MAX_ELEMENTS; i++) {
result[i] *= 3;
}
// 繰り上げ処理
for (int i = 0; i < MAX_ELEMENTS - 1; i++) {
if (result[i] >= BASE) {
result[i + 1] += result[i] / BASE;
result[i] %= BASE;
}
}
// 結果表示
print_result(result);
}
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNkZWZpbmUgTUFYX0RJR0lUUyA4IC8vIOmFjeWIl+OBruimgee0oOOBguOBn+OCiuOBruacgOWkp+ahgeaVsAojZGVmaW5lIE1BWF9FTEVNRU5UUyA4IC8vIOmFjeWIl+OBruimgee0oOaVsAojZGVmaW5lIEJBU0UgMTAwMDAwMDAgLy8gMTBeNywgN+ahgeWIhuOBruWApOOCkuihqOOBmeOBn+OCgeOBruWfuuaVsAoKLy8g57WQ5p6c44KS6KGo56S644GZ44KL6Zai5pWwCnZvaWQgcHJpbnRfcmVzdWx0KHVuc2lnbmVkIGxvbmcgcmVzdWx0W10pIHsKICAgIGludCBpLCBzdGFydGVkID0gMDsKICAgIGZvciAoaSA9IE1BWF9FTEVNRU5UUyAtIDE7IGkgPj0gMDsgaS0tKSB7CiAgICAgICAgaWYgKHN0YXJ0ZWQgfHwgcmVzdWx0W2ldICE9IDApIHsKICAgICAgICAgICAgaWYgKHN0YXJ0ZWQpCiAgICAgICAgICAgICAgICBwcmludGYoIiUwN2x1IiwgcmVzdWx0W2ldKTsgLy8gN+ahgeOBrjDln4vjgoHlh7rlipsKICAgICAgICAgICAgZWxzZQogICAgICAgICAgICAgICAgcHJpbnRmKCIlbHUiLCByZXN1bHRbaV0pOyAvLyDlhYjpoK3jga7opoHntKDjga8w5Z+L44KB44GX44Gq44GECiAgICAgICAgICAgIHN0YXJ0ZWQgPSAxOwogICAgICAgIH0KICAgIH0KICAgIGlmICghc3RhcnRlZCkKICAgICAgICBwcmludGYoIjAiKTsKICAgIHByaW50ZigiXG4iKTsKfQoKaW50IG1haW4oKSB7CiAgICB1bnNpZ25lZCBsb25nIHJlc3VsdFtNQVhfRUxFTUVOVFNdID0gezB9OyAvLyDntZDmnpzjgpLmoLzntI3jgZnjgovphY3liJcKICAgIHJlc3VsdFswXSA9IDE7IC8vIOWIneacn+WApDEKCiAgICBmb3IgKGludCBuID0gMDsgbiA8IDMwOyBuKyspIHsgLy8g57mw44KK6L+U44GX5Zue5pWw44KSMzDlm57jgajku67lrpoKICAgICAgICAvLyDlkITopoHntKDjgpIz5YCN44Gr44GZ44KLCiAgICAgICAgZm9yIChpbnQgaSA9IDA7IGkgPCBNQVhfRUxFTUVOVFM7IGkrKykgewogICAgICAgICAgICByZXN1bHRbaV0gKj0gMzsKICAgICAgICB9CgogICAgICAgIC8vIOe5sOOCiuS4iuOBkuWHpueQhgogICAgICAgIGZvciAoaW50IGkgPSAwOyBpIDwgTUFYX0VMRU1FTlRTIC0gMTsgaSsrKSB7CiAgICAgICAgICAgIGlmIChyZXN1bHRbaV0gPj0gQkFTRSkgewogICAgICAgICAgICAgICAgcmVzdWx0W2kgKyAxXSArPSByZXN1bHRbaV0gLyBCQVNFOwogICAgICAgICAgICAgICAgcmVzdWx0W2ldICU9IEJBU0U7CiAgICAgICAgICAgIH0KICAgICAgICB9CgogICAgICAgIC8vIOe1kOaenOihqOekugogICAgICAgIHByaW50X3Jlc3VsdChyZXN1bHQpOwogICAgfQoKICAgIHJldHVybiAwOwp9Cg==