// X ^ Y - 1 を GMPで求める
//
// gcc -lgmp -O3 でコンパイル
// [参考]
// http://d...content-available-to-author-only...e.jp/pyopyopyo/20090303/p1
// http://t...content-available-to-author-only...e.jp/data/gmplibrary.txt
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <gmp.h>
// main
int main()
{
unsigned long int xx, yy;
mpz_t result;
clock_t start, end;
// init
mpz_init(result);
// 入力
fprintf(stderr
, "X ^ Y - 1 を求めます。X, Y を \"X^Y\" の形式で入力してください\n :"); scanf("%d^%d", &xx
, &yy
); if (xx < 2 || yy < 1) {
}
// 計算
fprintf(stderr
, "計算開始 (%d ^ %d - 1 を求めます)\n", xx
, yy
); mpz_ui_pow_ui(result, xx, yy);
mpz_sub_ui(result, result, 1);
fprintf(stderr
, "計算終了 (%.3fs)\n", (double) (end
- start
) / CLOCKS_PER_SEC
);
// 出力
#if 1
FILE
*fp
= fopen("res.txt", "w"); mpz_out_str(fp, 10, result);
#else
gmp_printf("%Zd", result);
// ※ たいして時間は変わらない
#endif
fprintf(stderr
, "出力終了 (%.3fs)\n", (double) (end
- start
) / CLOCKS_PER_SEC
);
// 終了
mpz_clear(result);
return 0;
}
//
Ly8gWCBeIFkgLSAxIOOCkiBHTVDjgafmsYLjgoHjgosKLy8KLy8gZ2NjIC1sZ21wIC1PMyDjgafjgrPjg7Pjg5HjgqTjg6sKLy8gICBb5Y+C6ICDXQovLyAgICAgIGh0dHA6Ly9kLi4uY29udGVudC1hdmFpbGFibGUtdG8tYXV0aG9yLW9ubHkuLi5lLmpwL3B5b3B5b3B5by8yMDA5MDMwMy9wMQovLyAgICAgIGh0dHA6Ly90Li4uY29udGVudC1hdmFpbGFibGUtdG8tYXV0aG9yLW9ubHkuLi5lLmpwL2RhdGEvZ21wbGlicmFyeS50eHQKI2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPHRpbWUuaD4KI2luY2x1ZGUgPGdtcC5oPgoKLy8g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