这里是我试图去上班最后一行的代码是它失败:F#失败“错误这种表达预计将有一个int类型,但这里的类型为int - >诠释”
let rec gcd a b =
if b= 0 then
a
else
gcd b (a % b);;
let n = 8051
let mutable d = 0
let mutable c = 1
let mutable xi = 2
let mutable yi = 2
let f x = (pown x 2) + (c % n);;
while c < 100 do
while d = 1 do
xi <- (f xi)
yi <- (f(f(yi)))
printfn "%d%d" xi yi
d <- gcd(abs (xi - yi) n)
---------------------以下代码有效;除了在N个整数溢出---------
module Factorization
let rec gcd a b =
if b= 0 then
a
else
gcd b (a % b);;
let n = 600851475143N
let mutable d, c, xi, yi = 1, 1, 2, 2
let f x = (pown x 2) + (c % n);;
let maxN m =int(ceil(sqrt(float m)))
//if (n > maxN(xi)) && (n > maxN(yi)) then
while c < 100 do
d <- 1
while d = 1 do
if (maxN(n) > xi) && (maxN(n) > yi) then
xi <- f xi
yi <- f(f(yi))
d <- gcd (abs (xi - yi)) n
//fail
if d = n then d<-1
if d <> 1 then printfn "A prime factor of %d x = %d, y = %d, d = %d" n xi yi d
else
xi <- 2
yi <- 2
c <- c + 1;;
我认为你永远不会执行最后一行,因为你正在将d初始化为0,但是执行'while d = 1' :) – 2011-04-19 20:29:58
有趣的是,他不会经常执行最后一行infinitly,因为c永远不会改变,所以仍然是1,这是<100 – Ingo 2011-04-19 20:39:47
在测试ingo中发现 – n8CodeGuru 2011-04-21 16:04:13