## For positive real numbers $a,b$, an $a\times b$ torus is a rectangle of width $a$ and height $b$, with left and right sides identified, as well as top and bottom sides identified. In other words, when tracing a path on the rectangle, reaching an edge results in “wrapping round” to the corresponding point on the opposite edge.

A tiling of a torus is a way to dissect it into equilateral triangles of edge length 1. For example, the following three diagrams illustrate respectively a $1\times \frac{\sqrt{3}}{2}$ torus with two triangles, a $\sqrt{3}\times 1$ torus with four triangles, and an approximately $2.8432\times 2.1322$ torus with fourteen triangles:

Two tilings of an $a\times b$ torus are called equivalent if it is possible to obtain one from the other by continuously moving all triangles so that no gaps appear and no triangles overlap at any stage during the movement. For example, the animation below shows an equivalence between two tilings:

Let $F(n)$ be the total number of non-equivalent tilings of all possible tori with exactly $n$ triangles. For example, $F(6)=8$, with the eight non-equivalent tilings with six triangles listed below:

Let $G(N)=\sum_{n=1}^N F(n)$. You are given that $G(6)=14$, $G(100)=8090$, and $G(10^5)\equiv 645124048 \pmod{1\,000\,000\,007}$.

Find $G(10^9)$. Give your answer modulo $1\,000\,000\,007$.

### This question is a typical example of a Number Theory and Combinatorics problem, but it’s not very straightforward to derive an exact solution. Here’s a rough outline:

You can consider the problem as finding the number of non-isomorphic directed graphs that consists of exactly n nodes, which are divided into exactly two symmetry classes, and there is a directed edge between any two nodes belong to different classes. For a graph to be a valid tiling, it must be connected and Euler tour exists in the graph.

There is no fixed formula to calculate such kind of graphs directly. Many combinatorial problems like this can not be solved directly by mathematical deduction, instead, they’re usually solved by computer programs.

Given the restrictions of the problem (for example G(10^9) mod 1,000,000,007) and since the prompt provides calculated values of G(n) for specific numbers, we like to think that the problem is created for a competition involving programming.

An algorithm, given the graph is connected and Euler tour exists:

For a connected graph, if and only if the degree of every node is even, then an Euler tour exists in the graph.

So the algorithm goes this way:

1. For each non-isomorphic directed graphs that consist of exactly n nodes that are divided into two symmetry classes, count the ones which the degree of every node is even and record the number;

2. Since every graph corresponds exactly one status of tiling, sum up all the numbers above, then you get F(n);

3. To get G(n), sum up all F(i) where 1<=i<=n.
Keep in mind this is a rough guideline and the actual implementation details may change according to the problem requirements. The main problem you would encounter is how to effectively calculate the number and enumerating all the cases can be computational intensive.
To emphasize, typically this kind of problem would be solved using a computer programming language. Most popular choices include Python or C++. Then, these would be implemented using algorithms, data structures and programming techniques like dynamic programming or graph theory algorithms to solve. Given the combinatorial nature of the problem Python's itertools could be used or a similar library in the programming language of choice.

##### More Answers:

Digit Sum DivisionFreshman’s Product

Prime Factor and Exponent