-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathCRDS.cs
32 lines (27 loc) · 847 Bytes
/
CRDS.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using System;
// https://www.spoj.com/problems/CRDS/ #ad-hoc #sequence
// Counts cards in a typical card pyramid, modulo 1000007.
public static class CRDS
{
public static int Solve(int n)
{
long m = n;
// There are m - 1 floors with card counts 1, 2, ... m - 1, for:
long cardsFromFloors = m * (m - 1) / 2;
// There are m levels with card counts of 2, 4, ..., 2m, for (cancelling the 2s):
long cardsFromWalls = (m + 1) * m;
return (int)((cardsFromFloors + cardsFromWalls) % 1000007);
}
}
public static class Program
{
private static void Main()
{
int remainingTestCases = int.Parse(Console.ReadLine());
while (remainingTestCases-- > 0)
{
Console.WriteLine(
CRDS.Solve(int.Parse(Console.ReadLine())));
}
}
}