Project Euler #1: Multiples of 3 and 5

Sort by

recency

|

1471 Discussions

|

  • + 1 comment

    Has anyone solved this in C#?

    Test cases are bad, why don't they make the answer of the first case "2" just "0", works on my machine but does not work on their environment.

  • + 1 comment

    import sys

    def su(x,n): b=(n-1)//x c=b*((b+1)*x)/2 return int(c)

    t = int(input().strip()) for a0 in range(t): n = int(input().strip()) if (n in range(1,1000000001) and t in range(1,100001)): s=su(3,n)+su(5,n)-su(15,n) print(s)

    why is this not working

  • + 1 comment

    t = int(input().strip()) s=[] for a0 in range(t): n = int(input().strip()) s.append(n) u=s[0] v=s[1] s1=[] s2=[] for j in range(1,u): if(j%3==0 or j%5==0): s1.append(j)
    for j in range(1,v): if(j%3==0 or j%5==0): s2.append(j)
    print(sum(s1)) print(sum(s2))

  • + 0 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);
        }
    
  • + 0 comments

    Visit my site

    import Control.Applicative import Control.Monad import System.IO

    sumTo :: Integer -> Integer sumTo 0 = 0 sumTo n = (n * (n + 1)) div 2

    multSum :: Integer -> Integer multSum 0 = 0; multSum n = total_sum where three_max = n div 3; five_max = n div 5; fifteen_max = n div 15; three_mult = 3 * (sumTo three_max); five_mult = 5 * (sumTo five_max); fifteen_mult = 15 * (sumTo fifteen_max); total_sum = three_mult + five_mult - fifteen_mult

    main :: IO () main = do t_temp <- getLine let t = read t_temp :: Int forM_ [1..t] $ \a0 -> do n_temp <- getLine let n = read n_temp :: Integer let sum = multSum (n - 1) print (sum)