You are viewing a single comment's thread. Return to all comments →
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
sum1 = 3 * m1 * (m1 + 1) // 2 sum2 = 5 * m2 * (m2 + 1) // 2 sum3 = 15 * m3 * (m3 + 1) // 2 return sum1 + sum2 - sum3
if name == 'main': t = int(input().strip())
for t_itr in range(t): n = int(input().strip()) print(sum_of_multiples(n))
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 →
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())