You are viewing a single comment's thread. Return to all comments →
public static long checkPrime(int n){ long m3 = (n - 1) / 3; long sum3 = 3 * m3 * (m3 + 1) / 2;
long m5 = (n - 1) / 5; long sum5 = 5 * m5 * (m5 + 1) / 2; long m15 = (n - 1) / 15; long sum15 = 15 * m15 * (m15 + 1) / 2; return sum3 + sum5 - sum15; }
Seems like cookies are disabled on this browser, please enable them to open this website
I agree to HackerRank's Terms of Service and Privacy Policy.
Project Euler #1: Multiples of 3 and 5
You are viewing a single comment's thread. Return to all comments →
public static long checkPrime(int n){ long m3 = (n - 1) / 3; long sum3 = 3 * m3 * (m3 + 1) / 2;