You are viewing a single comment's thread. Return to all comments →
public static void mutiples(int n){ long m1 = (n-1)/3,m2 = (n-1)/5, m3 = (n-1)/15; long sum1 = 3*((m1*(m1+1)/2)), sum2 = 5*((m2*(m2+1)/2)), sum3 = 15*((m3*(m3+1)/2)); long sum = sum1+sum2-sum3; System.out.println(sum); }
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #1: Multiples of 3 and 5
You are viewing a single comment's thread. Return to all comments →