神奇的数字1:998001

如果你用1除以998001,你会得到000到999的所有三位数,除了998.

代码如下:

#include <iostream>
#include <mpir.h>
#include <mpirxx.h>

using namespace std;

int main()
{
    mpf_class f1;
    mpf_class f2;
    mpf_class f3;
    
    mp_bitcnt_t prec = 9952;

    mpf_set_prec(f1.get_mpf_t(), prec);
    mpf_set_prec(f2.get_mpf_t(), prec);
    mpf_set_prec(f3.get_mpf_t(), prec);

    f1 = 1;
    f2 = 21;
    f3 = f1 / f2;
    cout << "f1:" << f1 << endl;
    cout << "f2:" << f2 << endl;
    cout << "f3:" << f3 << endl;

    mp_bitcnt_t t = mpf_get_prec(f3.get_mpf_t());
    cout << "t:" << t << endl;

    mp_exp_t exp = 0;

    char *Val= mpf_get_str(NULL, &exp, 10, 0, f3.get_mpf_t());
    cout << "Val:0.000\n00" << Val << endl;
    cout << "exp:" << exp << endl;
    free(Val);
}
如果我们增加精度值,则会发现循环了,很奇妙的数字。
    mp_bitcnt_t prec = 20000;

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注