Skip to content

Commit

Permalink
Merge project euler
Browse files Browse the repository at this point in the history
  • Loading branch information
thaliaarchi committed Aug 1, 2019
2 parents 86c3230 + 0ae133c commit 7913039
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
7 changes: 7 additions & 0 deletions projecteuler/.gitignore
@@ -0,0 +1,7 @@
*.aux
*.fdb_latexmk
*.fls
*.log
*.out
*.pdf
*.synctex.gz
15 changes: 15 additions & 0 deletions projecteuler/problem_1.cpp
@@ -0,0 +1,15 @@
#include <iostream>

int problem1_s(unsigned int n, unsigned int d) {
unsigned int m = (n - 1) / d;
return d * m * (m + 1) / 2;
}

int problem1(unsigned int n) {
return problem1_s(n, 3) + problem1_s(n, 5) - problem1_s(n, 15);
}

int main() {
std::cout << problem1(1000) << std::endl;
return 0;
}
38 changes: 38 additions & 0 deletions projecteuler/problem_1.tex
@@ -0,0 +1,38 @@
\documentclass{article}
\usepackage{mathtools}
\usepackage{amsfonts}
\usepackage{amsmath}
\DeclarePairedDelimiter\ceil{\lceil}{\rceil}
\DeclarePairedDelimiter\floor{\lfloor}{\rfloor}

\begin{document}
\section{Multiples of 3 and 5}
Problem 1

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.

\begin{equation*}
\begin{split}
m &= \floor*{\frac{n-1}{d}} \\
s(n,d)
&= \sum\limits_{i=1}^{m} di \\
&= d\sum\limits_{i=1}^{m} i \\
&= d\frac{m(m + 1)}{2}
\end{split}
\end{equation*}
\begin{equation*}
\begin{split}
f(n) &= s(n, 3) + s(n, 5) - s(n, 15) \\
f(1000)
&= s(1000, 3) + s(1000, 5) - s(1000, 15) \\
&= 3\frac{333\cdot334}{2}
+ 5\frac{199\cdot200}{2}
- 15\frac{66\cdot67}{2} \\
&= 166833 + 99500 - 33165 \\
&= 233168
\end{split}
\end{equation*}
\end{document}

0 comments on commit 7913039

Please sign in to comment.