You are viewing a single comment's thread. Return to all comments →
handle long only:
public class Solution { public static void main(String[] args) { Scanner in = new Scanner(System.in); int t = in.nextInt(); for(int a0 = 0; a0 < t; a0++){ int n = in.nextInt()-1; //code below: long ans=(3*sum(n/3))+(5*sum(n/5))-(15*sum(n/15)); System.out.println(ans); //code above: } } public static long sum(long num){ return (num*(num+1))/2; } }
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 →
handle long only: