Project Euler #163: Cross-hatched triangles

  • + 0 comments

    public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); int result = calculateTriangleCount(n); System.out.println(result); }

    public static int calculateTriangleCount(int n) {
        return (1678 * n * n * n + 3117 * n * n + 88 * n - n % 2 * 345 - n % 3 * 320 - n % 4 * 90 - (n * n * n - n * n + n) % 5 * 288) / 240;
    }