私はC++で非常に大きな数(20桁以上)を因数分解するプログラムに取り組んでおり、オーバーフローの問題に対処するためにGMPを使用しています。私のプログラムは約10桁以下の数字でうまく機能していますが、15桁の数字を投げると爆発します。プログラムを次のように1行にまとめます。
#include <iostream>
#include <stdio.h>
#include <gmp.h>
#include <gmpxx.h>
using namespace std;
int main()
{
mpz_class n = 48112959837082048697; //this blows up
return 0;
}
その行を次のように置き換えると
mpz_class n = 12623773;
その後、すべてが正常に動作します。
エラーは次のとおりです。
$ g++ -o main main.cpp -lgmpxx -lgmp
main.cpp: In function ‘int main()’:
main.cpp:21:19: error: conversion from ‘long long int’ to ‘mpz_class’ is ambiguous
/usr/include/gmpxx.h:1563:3: note: candidates are: __gmp_expr<__mpz_struct [1], __mpz_struct [1]>::__gmp_expr(double)
/usr/include/gmpxx.h:1562:3: note: __gmp_expr<__mpz_struct [1], __mpz_struct [1]>::__gmp_expr(float)
/usr/include/gmpxx.h:1560:3: note: __gmp_expr<__mpz_struct [1], __mpz_struct [1]>::__gmp_expr(long unsigned int)
/usr/include/gmpxx.h:1559:3: note: __gmp_expr<__mpz_struct [1], __mpz_struct [1]>::__gmp_expr(long int)
/usr/include/gmpxx.h:1557:3: note: __gmp_expr<__mpz_struct [1], __mpz_struct [1]>::__gmp_expr(short unsigned int)
/usr/include/gmpxx.h:1556:3: note: __gmp_expr<__mpz_struct [1], __mpz_struct [1]>::__gmp_expr(short int)
/usr/include/gmpxx.h:1554:3: note: __gmp_expr<__mpz_struct [1], __mpz_struct [1]>::__gmp_expr(unsigned int)
/usr/include/gmpxx.h:1553:3: note: __gmp_expr<__mpz_struct [1], __mpz_struct [1]>::__gmp_expr(int)
/usr/include/gmpxx.h:1551:3: note: __gmp_expr<__mpz_struct [1], __mpz_struct [1]>::__gmp_expr(unsigned char)
/usr/include/gmpxx.h:1550:3: note: __gmp_expr<__mpz_struct [1], __mpz_struct [1]>::__gmp_expr(signed char)
誰かがこれを修正して大量に使用できるようにする方法を知っていますか?GMPは500桁プラスマイナスのようなものを許可することになっていると思いました。
ありがとう!