public static int PentagonNumbers(int n) { int min = int.MaxValue; List <long> pentagons = SpecialSequences.pentagonalnumbers(n); HashSet <long> hashpent = new HashSet <long>(pentagons); foreach (int k in pentagons) { foreach (int j in pentagons) { int tempsum = k + j; if (!hashpent.Contains(tempsum)) { continue; } int tempmin = k - j; if (!hashpent.Contains(tempmin)) { continue; } if (tempmin < min) { min = tempmin; } } } return(min); }
public static long TriangularPentagonalHexagonal(int n) { List <long> pentagon = SpecialSequences.pentagonalnumbers(n); List <long> hexagon = SpecialSequences.hexagonalnumbers(n); HashSet <long> penthash = new HashSet <long>(pentagon); for (int i = 143; i < hexagon.Count; i++) { if (penthash.Contains(hexagon[i])) { return(hexagon[i]); } } return(0); }