fork download
  1. using System.Numerics;
  2. using static IO;
  3. public class IO
  4. {
  5. public static IO Cin = new();
  6. public static StreamReader reader = new(Console.OpenStandardInput());
  7. public static StreamWriter writer = new(Console.OpenStandardOutput());
  8. public static implicit operator string(IO _) => reader.ReadLine();
  9. public static implicit operator char[](IO _) => reader.ReadLine().ToArray();
  10. public static implicit operator int(IO _) => int.Parse(reader.ReadLine());
  11. public static implicit operator double(IO _) => double.Parse(reader.ReadLine());
  12. public static implicit operator string[](IO _) => reader.ReadLine().Split();
  13. public static implicit operator int[](IO _) => Array.ConvertAll(reader.ReadLine().Split(), int.Parse);
  14. public void Deconstruct(out int a, out int b) { int[] r = Cin; (a, b) = (r[0], r[1]); }
  15. public void Deconstruct(out int a, out int b, out int c) { int[] r = Cin; (a, b, c) = (r[0], r[1], r[2]); }
  16. public static void Loop(int end, Action<int> action, int start = 0, in int add = 1) { for (; start < end; start += add) action(start); }
  17. public static object? Cout { set { writer.Write(value); } }
  18. public static object? Coutln { set { writer.WriteLine(value); } }
  19. public static void Main() { Program.Coding(); writer.Flush(); }
  20. }
  21. class Program
  22. {
  23. public static void Coding()
  24. {
  25. checked {
  26. List<BigInteger> fibo = new(capacity: 10_001) { 0,1 };
  27. for (int i = 2; i < fibo.Capacity; i++)
  28. {
  29. fibo.Add(fibo[^1] + fibo[^2]);
  30. }
  31.  
  32. Loop(1 + Cin, tc =>
  33. {
  34. (int p, int q) = Cin;
  35. Coutln = $"Case #{tc}: {fibo[p] % q}";
  36. }, 1);
  37. }
  38. }
  39. }
Success #stdin #stdout 0.08s 42732KB
stdin
10
5 10
6 25
10 21
32 43
100 100
50 50
25 25
45 67
109 32
128 128
stdout
Case #1: 5
Case #2: 8
Case #3: 13
Case #4: 15
Case #5: 75
Case #6: 25
Case #7: 0
Case #8: 19
Case #9: 9
Case #10: 69