/*****************************/
/* bignum.cプログラム */
/*****************************/
/* 多倍長整数の例題プログラム */
/* 3の累乗を計算します */
#include <stdio.h>
#include <math.h>
#define N 8 /* 解を格納する配列の要素数 */
#define ULIMIT 99 /* 累乗の繰り返し回数 */
#define RESLIMIT 10000000UL /* 7桁の符号なし整数の最大値+1 */
/* 関数のプロトタイプ宣言 */
void printresult(unsigned long result[]); /* 結果の出力 */
void power3(unsigned long result[]); /* 3を掛ける */
int main()
{
unsigned long result[N]={0}; /* 計算結果 */
int i; /* 繰り返しのカウンタ */
/* 初期値の設定 */
result[0]=1; /* 3の0乗 */
/* 累乗の計算 */
for(i=1;i<=ULIMIT;++i){
power3(result); /* 3を掛ける */
printresult(result); /* 結果の出力 */
}
return 0;
}
/**************************/
/* printresult()関数 */
/* 結果の出力 */
/**************************/
void printresult(unsigned long result[])
{
int j; /* 繰り返しのカウンタ */
for(j=N-1;j>=0;--j){
if(result
[j
]==0) printf(" "); /* 空白を8桁分出力 */ else printf("%8lu",result
[j
]); }
}
/*****************************/
/* power3() */
/* 3を掛ける */
/*****************************/
void power3(unsigned long result[])
{
int i;/* 繰り返しのカウンタ */
unsigned long midres[N]={0}; /* 3倍の計算結果 */
for(i=0;i<N;++i){
midres[i]+=result[i]*3;
if(midres[1]>=RESLIMIT){
if(i=N-1){midres[i+1]+=midres[i]/RESLIMIT;}
else{ /* 多倍長整数が桁あふれ */
fprintf(stderr
,"多倍長整数が桁あふれしました\n"); }
midres[i]=midres[i]%RESLIMIT;
}
}
/* 結果のresult[]への格納 */
for(i=0;i<N;++i)
result[i]=midres[i];
}
LyoqKioqKioqKioqKioqKioqKioqKioqKioqKioqLwovKiAgICAgIGJpZ251bS5j44OX44Ot44Kw44Op44OgICAgKi8KLyoqKioqKioqKioqKioqKioqKioqKioqKioqKioqLwoKLyog5aSa5YCN6ZW35pW05pWw44Gu5L6L6aGM44OX44Ot44Kw44Op44OgICovCi8qIDPjga7ntK/kuZfjgpLoqIjnrpfjgZfjgb7jgZkgKi8KCiNpbmNsdWRlIDxzdGRpby5oPgojaW5jbHVkZSA8bWF0aC5oPgoKI2RlZmluZSBOIDggLyog6Kej44KS5qC857SN44GZ44KL6YWN5YiX44Gu6KaB57Sg5pWwICovCiNkZWZpbmUgVUxJTUlUIDk5ICAvKiDntK/kuZfjga7nubDjgorov5TjgZflm57mlbAgKi8KI2RlZmluZSBSRVNMSU1JVCAxMDAwMDAwMFVMICAvKiA35qGB44Gu56ym5Y+344Gq44GX5pW05pWw44Gu5pyA5aSn5YCkKzEgKi8KCi8qIOmWouaVsOOBruODl+ODreODiOOCv+OCpOODl+Wuo+iogCAqLwp2b2lkIHByaW50cmVzdWx0KHVuc2lnbmVkIGxvbmcgcmVzdWx0W10pOyAvKiDntZDmnpzjga7lh7rlipsgKi8Kdm9pZCBwb3dlcjModW5zaWduZWQgbG9uZyByZXN1bHRbXSk7ICAvKiAz44KS5o6b44GR44KLICovCgppbnQgbWFpbigpCnsKCXVuc2lnbmVkIGxvbmcgcmVzdWx0W05dPXswfTsgIC8qIOioiOeul+e1kOaenCAqLwoJaW50IGk7ICAvKiDnubDjgorov5TjgZfjga7jgqvjgqbjg7Pjgr8gKi8KCQoJLyog5Yid5pyf5YCk44Gu6Kit5a6aICovCglyZXN1bHRbMF09MTsgIC8qIDPjga7vvJDkuZcgKi8KCQoJLyog57Sv5LmX44Gu6KiI566XICovCglmb3IoaT0xO2k8PVVMSU1JVDsrK2kpewoJCXBvd2VyMyhyZXN1bHQpOyAvKiDvvJPjgpLmjpvjgZHjgosgKi8KCQlwcmludGYoIm49JTNkOiAiLGkpOwoJCXByaW50cmVzdWx0KHJlc3VsdCk7ICAvKiDntZDmnpzjga7lh7rlipsgKi8KCX0KCXJldHVybiAwOwp9CgoKLyoqKioqKioqKioqKioqKioqKioqKioqKioqLwovKiAgICBwcmludHJlc3VsdCgp6Zai5pWwICAgKi8KLyogICDntZDmnpzjga7lh7rlipsgICAgICAgICAgICovCi8qKioqKioqKioqKioqKioqKioqKioqKioqKi8Kdm9pZCBwcmludHJlc3VsdCh1bnNpZ25lZCBsb25nIHJlc3VsdFtdKQp7CglpbnQgajsgIC8qIOe5sOOCiui/lOOBl+OBruOCq+OCpuODs+OCvyAqLwoJCglmb3Ioaj1OLTE7aj49MDstLWopewoJCWlmKHJlc3VsdFtqXT09MCkgcHJpbnRmKCIgICAgICAgICIpOyAvKiDnqbrnmb3jgpLvvJjmoYHliIblh7rlipsgKi8KCQllbHNlIHByaW50ZigiJThsdSIscmVzdWx0W2pdKTsKCX0KCXByaW50ZigiXG4iKTsKfQoKLyoqKioqKioqKioqKioqKioqKioqKioqKioqKioqLwovKiAgICAgcG93ZXIzKCkgICAgICAgICAgICAgICovCi8qICAgICAz44KS5o6b44GR44KLICAgICAgICAgICAgICovCi8qKioqKioqKioqKioqKioqKioqKioqKioqKioqKi8Kdm9pZCBwb3dlcjModW5zaWduZWQgbG9uZyByZXN1bHRbXSkKewoJaW50IGk7Lyog57mw44KK6L+U44GX44Gu44Kr44Km44Oz44K/ICovCgl1bnNpZ25lZCBsb25nIG1pZHJlc1tOXT17MH07IC8qIDPlgI3jga7oqIjnrpfntZDmnpwgKi8KCQoJZm9yKGk9MDtpPE47KytpKXsKCQltaWRyZXNbaV0rPXJlc3VsdFtpXSozOwoJCWlmKG1pZHJlc1sxXT49UkVTTElNSVQpewoJCQlpZihpPU4tMSl7bWlkcmVzW2krMV0rPW1pZHJlc1tpXS9SRVNMSU1JVDt9CgkJCWVsc2V7ICAgLyog5aSa5YCN6ZW35pW05pWw44GM5qGB44GC44G144KMICovCgkJCQlmcHJpbnRmKHN0ZGVyciwi5aSa5YCN6ZW35pW05pWw44GM5qGB44GC44G144KM44GX44G+44GX44GfXG4iKTsKCQkJCWV4aXQoMSk7ICAvKiDnlbDluLjntYLkuoYgKi8KCQkJfQoJCQltaWRyZXNbaV09bWlkcmVzW2ldJVJFU0xJTUlUOwoJCX0KCX0KCS8qIOe1kOaenOOBrnJlc3VsdFtd44G444Gu5qC857SNICovCglmb3IoaT0wO2k8TjsrK2kpCgkJcmVzdWx0W2ldPW1pZHJlc1tpXTsKfQ==