We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
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;
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #163: Cross-hatched triangles
You are viewing a single comment's thread. Return to all 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); }