Construction: Choose three pairwise parallel lines lA,lB,lC forming an infinite equilateral triangle prism (with side larger than 1). Split the n fireflies among the lines as equally as possible, and say that two fireflies are friends iff they lie on different lines.
To see this works:
1. Reflect lA and all fireflies on lA in the plane containing lB and lC.
2. Reflect lB and all fireflies on lB in the plane containing lC and lA.
3. Reflect lC and all fireflies on lC in the plane containing lA and lB.
...
Proof: Consider a valid configuration of fireflies. If there is no 4-clique of friends, then by Turán's theorem, there are at most f(n) pairs of friends.
Let g(n) be the answer, given that there exist four pairwise friends (say a,b,c,d). Note that for a firefly to move, all its friends must be coplanar.
**Claim (No coplanar K4) —** We can't have four coplanar fireflies which are pairwise friends.
Proof. If we did, none of them could move (unless three are collinear, in which case they can't move). □
Claim (Key claim — tetrahedrons don't share faces often) — There are at most 12 fireflies e which are friends with at least three of a,b,c,d.
Proof. First denote by A,B,C,D the locations of fireflies a,b,c,d. These four positions change over time as fireflies move, but the tetrahedron ABCD always has a fixed shape, and we will take this tetrahedron as our reference frame for the remainder of the proof.
WLOG, will assume that e is friends with a,b,c. Then e will always be located at one of two points E1 and E2 relative to ABC, such that E1ABC and E2ABC are two congruent tetrahedrons with fixed shape. We note that points D,E1, and E2 are all different: clearly D=E1 and E1=E2. (If D=E2, then some fireflies won't be able to move.)
Consider the moment where firefly a moves. Its friends must be coplanar at that time, so one of E1,E2 lies in plane BCD. Similar reasoning holds for planes ACD and ABD.
So, WLOG E1 lies on both planes BCD and ACD. Then E1 lies on line CD, and E2 lies in plane ABD. This uniquely determines (E1,E2) relative to ABCD:
* E1 is the intersection of line CD with the reflection of plane ABD in plane ABC.
* E2 is the intersection of plane ABD with the reflection of line CD in plane ABC.
Accounting for WLOGs, there are at most 12 possibilities for the set {E1,E2}, and thus at most 12 possibilities for E. (It's not possible for both elements of one pair {E1,E2} to be occupied, because then they couldn't move.) □
Thus, the number of friendships involving exactly one of a,b,c,d is at most (n−16)⋅2+12⋅3=2n+4, so removing these four fireflies gives
g(n)≤6+(2n+4)+max{f(n−4),g(n−4)}.
The rest of the solution is bounding. When n≥24, we have (2n+10)+f(n−4)≤f(n), so
g(n)≤max{f(n),(2n+10)+g(n−4)}∀n≥24.
By iterating the above inequality, we get
g(n)≤max{f(n),(2n+10)+(2(n−4)+10)+⋯+(2(n−4r)+10)+g(n−4r−4)},
where r satisfies n−4r−4<24≤n−4r.
Now
(2n+10)+(2(n−4)+10)+⋯+(2(n−4r)+10)+g(n−4r−4)=(r+1)(2n−4r+10)+g(n−4r−4)≤(4n−5)(n+37)+(224).
This is less than f(n) for n≥70, which concludes the solution.