2013-08-05 171 views
1

我正在解決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); 
    } 
} 

回答

3
mcs -r:System.Numerics.dll main.cs 

man mcs應該是你的榮譽。

根據您的單聲道版本,您可能想要使用dmcs和/或升級。

哦,這是BigInteger,不BigInt

+0

它顯示一條錯誤消息:「錯誤CS0006:元數據文件'System.Numerics.dll'找不到。」 – Stormboy

+0

我認爲'或升級'部分適用於此。這個對我有用。 (Ubuntu Raring) – sehe

+0

應該使用針對.NET 4配置文件的dmcs,http://www.mono-project.com/CSharp_Compiler –

3

您需要添加到System.Numerics.dll參考。

+2

我將如何做到這一點的單?我沒有使用任何IDE。只是編譯器工具。 – Stormboy

相關問題