Skip to content

Instantly share code, notes, and snippets.

#include <bits/stdc++.h>
#include <cassert>
using namespace std;
string s =
"08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08\n\
49 49 99 40 17 81 18 57 60 87 17 40 98 43 69 48 04 56 62 00\n\
81 49 31 73 55 79 14 29 93 71 40 67 53 88 30 03 49 13 36 65\n\
52 70 95 23 04 60 11 42 69 24 68 56 01 32 56 71 37 02 36 91\n\
22 31 16 71 51 67 63 89 41 92 36 54 22 40 40 28 66 33 13 80\n\
@dgodfrey206
dgodfrey206 / Summation of Primes.cpp
Created February 11, 2026 01:11
Find the sum of all the primes below two million.
#include <bits/stdc++.h>
#include <cassert>
using namespace std;
int main() {
int n = 2e6;
long long sum = 2;
for (int i = 3; i < n; i += 2) {
bool prime = true;
for (int j = 2; j * j <= i; j++) {
@dgodfrey206
dgodfrey206 / Special Pythagorean Triplet.cpp
Created February 11, 2026 00:43
There exists exactly one Pythagorean triplet for which a+b+c=100. Find the product abc.
#include <bits/stdc++.h>
using namespace std;
// find two numbers who's squares, when added, equal a number whose square root, plus those two numbers equals 1000
int main() {
cout << []{
int n = 1000;
for (int a = 1; a <= n; a++) {
for (int b = a + 1; b <= n; b++) {
@dgodfrey206
dgodfrey206 / Largest Product in a Series.cpp
Created February 10, 2026 17:47
Find the thirteen adjacent digits in the 1000-digit number that have the greatest product. What is the value of this product?
#include <bits/stdc++.h>
using namespace std;
string num = "73167176531330624919225119674426574742355349194934\
96983520312774506326239578318016984801869478851843\
85861560789112949495459501737958331952853208805511\
12540698747158523863050715693290963295227443043557\
66896648950445244523161731856403098711121722383113\
62229893423380308135336276614282806444486645238749\
30358907296290491560440772390713810515859307960866\
@dgodfrey206
dgodfrey206 / 10001st Prime.cpp
Created February 10, 2026 17:13
What is the 10001st prime number?
#include <bits/stdc++.h>
#include <cassert>
using namespace std;
int main() {
int n = 10001;
int limit = n/2;
vector<int> prime;
while (true) {
@dgodfrey206
dgodfrey206 / sum_square_difference.cpp
Created February 10, 2026 15:49
Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.
#include <bits/stdc++.h>
#include <cassert>
using namespace std;
int main() {
int n = 100;
int result = (n * (n + 1) * (3 * n * (n + 1) - 2 * (2 * n + 1)))/12;
cout << result;
}
@dgodfrey206
dgodfrey206 / smallestmultiple.cpp
Created February 10, 2026 05:59
2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?
#include <bits/stdc++.h>
#include <cassert>
using namespace std;
int main() {
int n = 40;
while (true) {
bool found = true;
for (int i = 2; i <= 20; i++) {
if (n % i != 0) {
@dgodfrey206
dgodfrey206 / largestprimefactor.cpp
Last active February 10, 2026 05:11
The prime factors of 13195 are 5,7,13 and 29. What is the largest prime factor of the number 600851475143?
#include <bits/stdc++.h>
#include <cassert>
using namespace std;
using ll = long long;
int sieve() {
ll n = 600851475143;
ll sz = sqrt(n);
vector<bool> prime(sz, true);
#include<vector>
#include<functional>
#include <bits/stdc++.h>
using namespace std;
enum ScalarType {
UINT8,
Float,
Byte,
};
@dgodfrey206
dgodfrey206 / split.cpp
Created December 27, 2025 19:51
Split argument list
#include <utility>
#include <string>
#include <tuple>
#include <print>
#include <functional>
#include <concepts>
#include <memory>
#include <iostream>
namespace detail {