关于787的特别之处是什么?

时间:2017-07-12 21:43:21

标签: haskell integer-arithmetic

在ghci中,使用arithmoi包:

Process p = new Process();                    

//assigned from the form txtboxes to the UserInformation class 
userInfo.Username = txt_Username.Text;
userInfo.Password = txt_Password.Text;

//string variabes for the cmd arguments
string leMars21StArguments = @"/C C:\PowerShellRemotly\PsExec.exe -i " + 
    @"\\VML-2012-QBOOK2 -u mydomain\" + userInfo.Username + " -p " + 
    userInfo.Password + " -d C:\\batch\\myfile.bat";

if (userInfo.Username == string.Empty)
{
    MessageBox.Show("Username cannot be null, please try again");
}

if (userInfo.Password == string.Empty)
{
    MessageBox.Show("Password cannot be null, please try again");
}

if (cmb_DatabaseSelection.SelectedItem == "location")
{
    p.StartInfo.FileName = "cmd.exe";
    p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
    p.StartInfo.CreateNoWindow = true;
    p.StartInfo.Arguments = leMars21StArguments;
    p.StartInfo.RedirectStandardOutput = true;
    p.StartInfo.UseShellExecute = false;
    p.StartInfo.RedirectStandardError = true;

    p.Start();
    string output = p.StandardOutput.ReadToEnd();
    string errOutput = p.StandardError.ReadToEnd();
    p.Close();

    MessageBox.Show(errOutput);
}

五分钟后,它仍然没有响应。为什么需要这么长时间?

(从一些临时测试来看,对于大于787的所有选择来说似乎都很慢,而对于所有选择较小的选择来说,它会很快。)

1 个答案:

答案 0 :(得分:23)

arithmoi implements integerRoot通过获得初始近似根并用牛顿方法改进其猜测。对于(10 32 786 ,第二个近似得到了一个非常好的起点:

> appKthRoot 786 ((10^32)^786)
100000000000000005366162204393472

对于(10 32 787 ,第二个近似得到一个非常糟糕的起点。就像,真的坏。

> appKthRoot 787 ((10^32)^787)   
1797693134862315907729305190789024733617976978942306572734300811577326758055009
6313270847732240753602112011387987139335765878976881441662249284743063947412437
7767893424865485276302219601246094119453082952085005768838150682342462881473913
110540827237163350510684586298239947245938479716304835356329624224137216

它实际上得到了从那里开始的一切的近似值。

> length $ nub [appKthRoot x ((10^32)^x) | x <- [787..1000]]
1

无论如何,输入the important parts of appKthRoot,我们得到:

> let h = 106; k = 786; n = (10^32)^k; !(I# s) = h * k - k in floor (scaleFloat (h - 1) (fromInteger (n `shiftRInteger` s) ** (1/fromIntegral k) :: Double))
100000000000000005366162204393472

> let h = 106; k = 787; n = (10^32)^k; !(I# s) = h * k - k in floor (scaleFloat (h - 1) (fromInteger (n `shiftRInteger` s) ** (1/fromIntegral k) :: Double))
179769313486231590772930519078902473361797697894230657273430081157732675805500963132708477322407536021120113879871393357658789768814416622492847430639474124377767893424865485276302219601246094119453082952085005768838150682342462881473913110540827237163350510684586298239947245938479716304835356329624224137216

并了解scaleFloat

的内容
> let h = 106; k = 786; n = (10^32)^k; !(I# s) = h * k - k in fromInteger (n `shiftRInteger` s) ** (1/fromIntegral k) :: Double
2.465190328815662

> let h = 106; k = 787; n = (10^32)^k; !(I# s) = h * k - k in fromInteger (n `shiftRInteger` s) ** (1/fromIntegral k) :: Double
Infinity
是的,那就是这样做的。 (10 32 786 ÷2 82530 ≈2 1023.1 适合双重,但(10 32 787 ÷2 82635 ≈2 1024.4 没有。