[ACM]Q10229: Modular Fibonacci
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Numerics;
namespace Q10229
{
class Program
{
static private int[] iarr; static private char[] par = { ' ' }; static private BigInteger[] fib; static private BigInteger m;
static void Main(string[] args)
{
for (; ; )
{
label: Console.Write("m n>>>");
try
{
iarr = Array.ConvertAll<string, int>(Console.ReadLine().Split(par, StringSplitOptions.RemoveEmptyEntries), int.Parse);
if (iarr.Length != 2) throw new Exception();
}
catch
{
goto label;
}
if (iarr[0] == 0) { Console.WriteLine("Ans=0"); goto label; }
else if (iarr[0] == 1) { Console.WriteLine("Ans=1"); goto label; }
fib = new BigInteger[iarr[0] + 1];
fib[0] = 0; fib[1] = 1; m = 1;
for (int i = 2; i <= iarr[0]; i++)
fib[i] = fib[i - 2] + fib[i - 1];
for (int i = 0; i < iarr[1]; i++) m *= 2;
Console.WriteLine("Ans={0}", fib[iarr[0]] % m);
}
}
}
}