我正在解決Project Euler上的problem 25。我用C#編寫了一個代碼。但是在這種情況下,我需要使用「BigInt」,因爲Int64的大小不足以保存數字。但是,當我放入using System.Numerics;
時,它會在編譯期間給出錯誤消息(標題中的消息)。爲什麼是這樣?我正在使用單聲道2.10.9。名稱空間'系統'中不存在類型或名稱空間名稱'Numerics'
我的代碼:
using System;
using System.Numerics;
public class Problem_25{
static BigInt fib(int n){
double Phi = (1+Math.Sqrt(5))/2;
double phi = (1-Math.Sqrt(5))/2;
BigInt an = Convert.BigInt((Math.Pow(Phi, n)-(Math.Pow(phi, n)))/Math.Sqrt(5));
return an;
}
static void Main(){
int i = 100;
int answer = 0;
string current_fn = "1";
while(true){
current_fn = Convert.ToString(fib(i));
if(current_fn.Length == 1000){
answer = i;
break;
}
else{
i++;
}
}
Console.WriteLine("Answer: {0}", answer);
}
}
它顯示一條錯誤消息:「錯誤CS0006:元數據文件'System.Numerics.dll'找不到。」 – Stormboy
我認爲'或升級'部分適用於此。這個對我有用。 (Ubuntu Raring) – sehe
應該使用針對.NET 4配置文件的dmcs,http://www.mono-project.com/CSharp_Compiler –