### Prime Factors 2

``````#include <map>
std::map<int, int> prime_factors(int n) {
auto factors = std::map<int, int>{};

while (n % 2 == 0) {
factors[2]++;
n = n / 2;
}

for (auto p = 3; p * p <= n; p += 2) {
while (n % p == 0) {
factors[p]++;
n = n / p;
}
}

if (n > 1) {
factors[n]++;
n = n / 1;
}

return factors;
}``````

### Prime Factors

``````#include <vector>

std::vector<int> prime_factors(int n) {
auto factors = std::vector<int>{};
if (n == 0) { return factors; }
while (n % 2 == 0) {
factors.push_back(2);
n = n / 2;
}

for (auto p = 3; p * p <= n ; p += 2) {
while (n % p == 0) {
factors.push_back(p);
n = n / p;
}
}

if (n > 2) {
factors.push_back(n);
}
return factors;
}``````

### Digest word into letters (C++ Translation)

Fundamentals
Strings
Code
Diff
• ``````#include <string>
#include <fmt/ranges.h>

auto digest(const std::string& param) {
if (param.empty()) return param; // Oh... should check there !!
return fmt::format("{}", fmt::join(param, " "));
}``````
• #include <string>
• #include <numeric>
• #include <fmt/ranges.h>
• auto digest(const std::string& param) {
• if (param.empty()) return param; // Oh... should check there !!
• return std::accumulate(std::next(param.cbegin()),param.cend(),
• std::string(1,param[0]), // Char initializer
• [](auto &s, auto c) {
• return s+std::string{{' ',c}}; // initializer_list string initializer
• });
• return fmt::format("{}", fmt::join(param, " "));
• }

### Return 1!

Code
Diff
• ``````def should_return_1():
return (1 << 2) ^ (1 << 2) | 1

``````
• def should_return_1():
• return 2 - 1
• return (1 << 2) ^ (1 << 2) | 1

### Number - 7

Code
Diff
• ``````class Solution:
def __init__(self, n):
self.n = n

def number_se7en(self):
return self.n // 7 + 1
``````
• class Solution:
• def __init__(self, n):
• self.n = n
• self.n = n
• def number_se7en(self):
• return (self.n - 1) // 7 + 1
• return self.n // 7 + 1

### Return 1!

Code
Diff
• ``````def should_return_1():
return 0xFF >>  0x7``````
• def should_return_1():
• x = 212312321213125212312321213125 - 212312321213125212312321213124
• return x
• return 0xFF >> 0x7

### Return 1!

Code
Diff
• ``````def should_return_1():
return (3 + 1 + 1) - (3 + 1 + 0)

``````
• def should_return_1():
• return (9999 * 9999 * 9999 * 9999 * 9999 * 9999) ** 0
• return (3 + 1 + 1) - (3 + 1 + 0)

### Return 1!

Code
Diff
• ``````def should_return_1():
return (9999 * 9999 * 9999 * 9999 * 9999 * 9999) ** 0

``````
• def should_return_1():
• return int(str(int(bin(76)[2:]) & int(bin(7)[2:]))[:1])
• return (9999 * 9999 * 9999 * 9999 * 9999 * 9999) ** 0

### Return 1000, keeping n immutable

Code
Diff
• ``thousand = lambda n = 8: (4 << 4) | (5 << 5) | (6 << 6) | (7 << 7) | n``
• thousand = lambda n = 8: (n << 7) - (n << 1) - n
• thousand = lambda n = 8: (4 << 4) | (5 << 5) | (6 << 6) | (7 << 7) | n

### Return 100

Code
Diff
• ``````def return_hundred():
return (3 << 5) | (1 << 2)``````
• def return_hundred():
• return [int(x) for x in [bin(True+True+True+True)[True+True:]]][False]
• return (3 << 5) | (1 << 2)

### Return 100

Code
Diff
• ``````def return_hundred():
return (9 * 8 + 7 + 6 + 5 + 4 + 3 + 2 + 1)``````
• def return_hundred():
• if 8 == 0:
• return 100 + 10
• else:
• return 100 - 0 + 0 - 0
• return (1829-1762+21)/100 + 99.12
• return (9 * 8 + 7 + 6 + 5 + 4 + 3 + 2 + 1)

### Return 1000, keeping n immutable

Code
Diff
• ``thousand = lambda n = 8: (n << 7) - (n << 1) - n``
• thousand = lambda n = 8: n * 125
• thousand = lambda n = 8: (n << 7) - (n << 1) - n

### Return 1000, keeping n immutable

Code
Diff
• ``thousand = lambda n = 8: n * 125``
• thousand = lambda: 1000
• thousand = lambda n = 8: n * 125

### Return 1000, keeping n immutable

Code
Diff
• ``````def thousand(n=8):
return sum(n * x for x in range(15, 40, 5))``````
• def thousand(n=8):
• return [i + (n * 1 + 2) ** 3 for i in range((n * 1 + 2)+5)][0]
• return sum(n * x for x in range(15, 40, 5))

### Return 1000, keeping n immutable

Code
Diff
• ``````def thousand(n=8):
return (100 * n) + (20 * n) + (5 * n)``````
• def thousand(n=8):
• return [i + (n * 1 + 2) ** 3 for i in range((n * 1 + 2)+5)][0]
• return (100 * n) + (20 * n) + (5 * n)