我想使用System.Numerics中的BigInteger类,但如果我想写
using System.Numerics;
Run Code Online (Sandbox Code Playgroud)
Numerics找不到.我在网上搜索,发现我必须添加一个引用System.Numerics.dll,但是我该怎么做呢?
我已经开始关注Project Euler问题了.目前我在问题13,它要求您提供100个,50个数字之和的前十位数字.
我决定尝试用C#中的一个大型int来解决它.我在互联网上环顾四周,有大量的示例代码.但是,我似乎无法在Visual Studio 2010中找到BigInt.
我在Project Euler上解决问题25.我在C#中为它编写了一个代码.但是在这种情况下,我需要使用"BigInt",因为Int64不足以容纳数字.但是,当我放置时,它会在编译期间给出错误消息(标题中的消息).为什么是这样?我使用的是Mono 2.10.9.using System.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);
}
}
Run Code Online (Sandbox Code Playgroud)