Skip to content

Instantly share code, notes, and snippets.

@aoisensi
Created September 23, 2013 23:35
Show Gist options
  • Save aoisensi/6678457 to your computer and use it in GitHub Desktop.
Save aoisensi/6678457 to your computer and use it in GitHub Desktop.
using System;
using System.Numerics;
class Program
{
private static BigInteger fib(int n)
{
Func<BigInteger, BigInteger, int, BigInteger> fn = null;
fn = (x, y, i) => (i > 0 ? fn(y, x + y, i - 1) : y);
return fn(new BigInteger(1), new BigInteger(0), n);
}
static void Main(string[] args)
{
string input;
while ((input = Console.ReadLine()) != "")
{
int n;
if (!int.TryParse(input, out n)) break;
Console.WriteLine(fib(n));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment