Fix $n>4$. Is there a characterization of the set $T_n$ of all natural numbers $t$ such that there is some graph on $n$ vertices with exactly $t$ distinct triangles? For example, it's clear that {$1,2,\ldots,n$} $\subseteq T_n$ and $\binom{n}{3}1 \notin T_n$; what else can we say?

I will argue that the following are true:
For $n \gt 14$ the largest members of $T_n$ are precisely
A simple construction and simple bounds are enough to show that $T_n$ contains all integers less than $\binom{n}{3}n^2.$ The same simple construction with more sophisticated bounds evidently shows that for any $\epsilon \gt 0$ and all large enough $n$, $T_n$ contains all integers less than $\binom{n}{3}\epsilon n^2.$ First a side result. Every integer can be expressed as a sum of three triangular numbers. I asked elsewhere : What is the smallest positive integer $s=s_m$ which can not be written in the form $$s=\binom{a}{2}+\binom{b}{2}+\binom{c}{2}$$ subject to $\max(a,b,c) \le m?$ For now I will say that obviously, for all $m $, $s_m \ge \binom{m+1}{2} .$ Consider this simple construction: Start with $K_{n3}$ which already has $\binom{n3}{3}$ triangles. Adjoin three further vertices $u,v,w$ with no edges between them but allow each to be connected to all, some or none of the other $n3$ vertices. This will allow all triangle counts of the form $\binom{n3}{3}+\binom{a}{2}+\binom{b}{2}+\binom{c}{2}$ subject to $\max(a,b,c) \le n3$ and hence at least everything from $\binom{n3}{3}$ up to $\binom{n3}{3}+\binom{n2}{2}1=\binom{n}{3}(n^25n+8).$ We may assume by inductive hypothesis and a few very small examples that using $n1$ or less vertices we can get all counts up to $\binom{n1}{3}((n1)^25(n1)+8)=\binom{n3}{3}+n5.$ Hence we can get all counts from $0$ up to $\binom{n}{3}(n^25n+8)$ using this construction. If I understand a rather impressive answer (in a comment) to my question, for any $\epsilon \gt 0$, $s_m \ge (3/2\epsilon)m^2$ for all large enough $m.$ Hence for large enough $n$ we can get all counts up to $\binom{n3}{3}+(3/2\epsilon)(n3)^2=\binom{n}{3}(\epsilon n^2+O(n)).$ Consider now the largest counts in $T_n.$ They must result from removing only a few edges from $K_n$. Suppose that $c$ edges are removed and let $H$ be the graph formed by the removed edges. If $H$ is $c$ disjoint edges, this kills $c(n2)$ triangles. In general the number of killed triangles is $c(n2)p2t$ where $t$ is the number of triangles in H (since these triples get counted three times by $c(n2)$) and $p$ is the number of paths of length two in $H$ which are not part of a triangle in $H.$ To find the exact spectrum of values requires not an enumeration but simply a classification of which triples $c,p,t$ represent possible values for the edge,path and triangle count of graph. Hence all triangle free graphs with $v$ vertices, $c$ edges and degree sequence $d_1,d_2,\cdots,d_v$ give (when removed) the same count: $\binom{n}{3}\sum_1^v\binom{d_i}{2}.$ We need not know how many ways a certain degree sequence can be obtained, only if it can be realized in at least one one. 


As Gerhard Paseman mentions, this may be as hard as enumerating all graphs. If that is indeed the case, you may want to check out this paper by Alon, Yuster and Zwick. In it, they mention that given a graph $G=(V,E)$, it is easy to count the number of triangles in $G$ in $O(V^\omega)$time, where $\omega<2.376$ is the exponent of matrix multiplication. They generalize this by presenting an $O(V^\omega)$ algorithm for counting the number of $k$cycles in a graph for $k \leq 7$. An elegant technique in this area is the socalled colourcoding method. Edit 1. A partial answer to unknown's question is that, $k \in T_n$ for all $k \leq n^{3/2}$ ($n$ large). To see this choose $j$ maximal such that $\binom{j}{3} \leq k$. By making a clique on $j$ vertices, and then taking a disjoint union of triangles on the remaining vertices, we can make a graph with exactly $k$ triangles provided $k\binom{j}{3} \leq \frac{nj}{3}$. After some number crunching, this is possible provided $k \leq n^{3/2}$. Edit 2. Here is some information for $k$ which are not in $T_n$. As Gerhard notes, removing an edge from $K_n$ destroys exactly $n2$ triangles. Thus, $\binom{n}{3}  t \notin T_n$ for all $t=1, \dots, n3$. The next triangledensest graph is obtained by removing two incident edges, which destroys $2n5$ triangles. Thus, $\binom{n}{3}  t \notin T_n$, for $t=n1, n, \dots, 2n6$. The next two triangledensest graphs are obtained by removing a matching of size 2, which destroys $2n4$ triangles, or the edges of a triangle, which destroys $3n8$ triangles. Thus, $\binom{n}{3}t \notin T_n$ for $t=2n3, 2n2, \dots, 3n9$. 


We can give a construction showing that all counts up to $(1+o(1))\binom n3$ can be obtained, confirming Terry's probabilistic approach. Consider graphs consisting, apart from isolated vertices, of a sequence of cliques of size 3 or more, where each clique overlaps the previous one in two edges and otherwise has new vertices. If the cliques have size $k_1,k_2,\ldots,k_m$, then the number of triangles is $t=\sum_{i=1}^m \binom{k_i}{3}$ and the number of vertices is $n\ge 2+\sum_{i=1}^m (k_i2)$. So the question is, for which $n,t$ do these inequalities have a solution $k_1,k_2,\ldots,k_m$? Turn it around and ask: given $t$, what is the least $n$ for which there is a solution? (Larger $n$ are obtained by adding isolated vertices.) An upper bound is given by the greedy solution $n=N(t)$: choose $k_1$ to be as large as possible with $\binom{k_1}{3}\le t$ and continue recursively in the same manner. Since $t\binom{k_1}{3}=O(t^{2/3})$, the $k_1$clique dominates $N(t)$. To get an explicit bound needs some care, but wouldn't be difficult. I'm pretty sure it shows that, for large $n$, there is a solution for $0\le t\le\binom n3O(n^2)$. ADDED: Here are some tentative values of $[n,\Delta_n]$, where the first missing number of triangles is $\binom n3\Delta_n$. From $n=13$ onwards, I won't swear to them. I just computed all the graphs within 16 edges of a complete graph and counted their triangles. Most seriously, I only eyeballed the output for missing values and could have missed some. The larger values are wobbling around near 0.3 $n^2$. [4, 1], [5, 4], [6, 6], [7, 11], [8, 19], [9, 23], [10, 27], [11, 31], [12, 42], [13, 47], [14, 52], [15, 66], [16, 72], [17, 78], [18, 98], [19, 105], [20, 112] 


I don't know that it would be as hard as enumerating all graphs. There are more than $2^{\binom{n}2}/n!$ graphs but less than $\binom{n}{3}$ possiblities for the number of triangles. Perhaps not a lot fewer though. $T_4=\{0,1,2,4\}.$ Removing $k=0,1,2$ disjoint edges yields $\binom{n}{3}k(n2)$ triangles and removing $2$ nondisjoint edges $\binom{n}{3}2(n2)+1.$ These will be the largest four numbers in $T_n$ so $T_5=\{0,1,2,3,4,5,7,10\}.$ It starts to seem easier to have $U_n=\{x \mid 0 \lt\binom{n}{3}x \notin T_n \}$ so $U_5=\{1,2,4\}.$ The previous comment is that $U_n$ contains all the integers from $1$ to $2n6$ with the exception of $n2.$ Once $n \ge 6$ there are $4$ possible cases for removing $3$ edges yielding $\binom{n}{3}3(n2)+j$ for $j=0,1,2,3$ Putting this together with the previous observations and the fact that $T_5 \subset T_6$ is enough to establish that $T_6=\{0,1,2,3,4,5,6,7,8,9,10,11,12,13,16,20\}$ so $U_6=\{1,2,3,5,6\}$ The reference given by arun, if correct (which I have no reason to doubt) gives $U_7=\{1,2,3,4,6,7,8,11 \}$ and $U_8=\{1,2,3,4,5,7,8,9,10,13,14,19\}.$ I'll let someone else check the intermediate cases. The last one (if I have not made an error) says that $U_{12}=\{1,2,3,4,5,6,7,8,9,11,12,13,14,15,16,17,18,21,22,23,24,25,26,31,32,33,35,41,42\}$ f LATER As Gerhard notes, so far I used an enumeration of all graphs with 3 edges along with a reported enumeration of all graphs with up to $12$ nodes (although only the statistics which gave nonzero counts, not the counts themselves). However less detailed constructions might yield most of the values. Here is one: Consider splitting $n$ nodes into two groups, of sizes $3$ and $m=n3.$ Decree a complete graph $K_m$ on the $m$ nodes and no edges joining two of the other $3.$ Then with the between group edges one can obtain any triangle count $\binom{m}{3}+\sum_{i=1}^3\binom{m_i}{2}$ for any choices of $m_i \le m.$ This (together with the fact that $T_{n1} \subset T_n$) shows that $T_n$ contains all integers up to $\binom{n2}{3}$ (and further but not all the way to $\binom{n1}{3})$ (Any integer is a sum of three or less triangular numbers). So this gets us to $O(\binom{n}{3})$ without any enumeration. Other constructions might get further. 


Is it true that for sufficiently large $n$, $\{1,...,n^2\}\subset T_n$? The number of unlabelled graphs with a given number of triangles is explicitly detailed here for $n \in \{1,...,12\}$: http://www.win.tue.nl/~aeb/graphs/cospectral/triangles.html 

