You are viewing a single comment's thread. Return to all comments →
public static long sum(int n){ n--; long sum=0; long n3 = n/3; long n5 = n/5; long n15 = n/15; sum=(3*n3*(n3+1))/2 + (5*n5*(n5+1))/2 - (15 * n15*(n15+1))/2; return sum; } sum=(3*n3*(n3+1))/2 + (5*n5*(n5+1))/2 - (15 * n15*(n15+1))/2; return 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 →
//here is the exact JAVA solution by using formula for the sum of an arithmetic progression//