2013-08-05 172 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

相关问题