Coding challenges are a great resource for learning coding techniques and improve analytical thinking, this is a collection of challenges from different platforms.
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
Find the sum of all the multiples of 3 or 5 below 1000.
Sample 00
Sample 01
input01.txt
1000
output01.txt
233168
Solution
main.go
package main
import (
"fmt"
)
func main() {
var n int
fmt.Scan(&n)
n = n - 1
fmt.Println(SummationBy(n, 3) + SummationBy(n, 5) - SummationBy(n, 15))
}
func Summation(n int) int {
return n * (n + 1) / 2
}
func SummationBy(n, m int) int {
return Summation(n/m) * m
}
Privacy policy
This site does not use third-party tracking cookies!
If you use private source products, worrying about privacy and using this products is like worrying about global warming and not recycling.. So just don’t.. 😒