We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Project Euler #1: Multiples of 3 and 5
Project Euler #1: Multiples of 3 and 5
Sort by
recency
|
1473 Discussions
|
Please Login in order to post a comment
import math import os import random import re import sys
def sum_of_multiples(n): m1 = (n - 1) // 3 m2 = (n - 1) // 5 m3 = (n - 1) // 15
if name == 'main': t = int(input().strip())
def helper(n,k): p=(k-1)//n return n*p*(p+1)//2
def multiple(number): return ( helper(3,number) +helper(5,number)-helper(15,number) ) this function has passed all the test cases as it eliminates the use of traditional for loops and use of mathematical expressions
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.
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
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))