competitive programming ⚔️ resources and notes 🤺
ios::sync_with_stdio(false);
cin.tie(nullptr);
C/C++ Type | Rust Type | Size | Minimum | Maximum |
---|---|---|---|---|
uint8_t | u8 | 8-bit | ||
uint16_t | u16 | 16-bit | ||
uint32_t | u32 | 32-bit | ||
uint64_t | u64 | 64-bit | ||
u128 | 128-bit | |||
int8_t | i8 | 8-bit | ||
int16_t | i16 | 16-bit | ||
int32_t | i32 | 32-bit | ||
int64_t | i64 | 64-bit | ||
i128 | 128-bit | |||
size_t | isize | arch | ||
ssize_t | usize | arch | ||
float | f32 | 32-bit | ||
double | f64 | 64-bit |
Bit manipulation3
$x \cdot 2^k = x \ll k$ $x / 2^k = x \gg k$
- set —
$x \lor (1 \ll n)$ - unset —
$x \land \lnot(1 \ll n)$ - toggle —
$x \oplus (1 \ll n)$
Operation | C/C++ Syntax | Rust Syntax | LaTex | LaTex (Rendered) |
---|---|---|---|---|
Addition | x + y |
x + y |
+ |
|
Subtraction | x - y |
x - y |
- |
|
Multiplication | x * y |
x * y |
\cdot |
|
Division | x / y |
x / y |
/ |
|
Remainder | x % y |
x % y |
\bmod |
|
Exponentiation | pow |
T::pow |
^ |
|
Square root | sqrt |
T::sqrt |
\sqrt{} |
|
|
\sqrt[]{} |
Operation | C/C++ Syntax | Rust Syntax | LaTex | Latex (Rendered) |
---|---|---|---|---|
Equality | x == y |
x == y |
= |
|
Approximate-equality | \approx |
|||
Inequality | x != y |
x != y |
\neq |
|
Greater than | x > y |
x > y |
> |
|
Less than | x < y |
x < y |
< |
|
Greater than or equal | x >= y |
x >= y |
\geq |
|
Less than or equal | x <= y |
x <= y |
\leq |
Operation | C/C++ Syntax | Rust Syntax | LaTex | LaTex (Rendered) |
---|---|---|---|---|
Bitwise NOT | ~x |
!x |
\lnot |
|
Bitwise AND | x & y |
x & y |
\land |
|
Bitwise OR | x | y |
x | y |
\lor |
|
Bitwise XOR | x ^ y |
x ^ y |
\oplus |
|
Bitwise left shift | x << n |
x << n |
\ll |
|
Bitwise right shift | x >> n |
x >> n |
\gg |
|
Bitwise left rotate |
std::rotl C++20
|
T::rotate_left |
\lll |
|
Bitwise right rotate |
std::rotl C++20
|
T::rotate_right |
\ggg |
Constant | C/C++ Syntax | Rust Syntax | LaTeX | LaTeX (Rendered) |
---|---|---|---|---|
true | true |
true |
\top |
|
false | false |
false |
\bot |
|
Archimedes' constant | M_PI |
PI |
\pi |
|
Euler's number | M_E |
E |
e |
|
The full circle constant | TAU |
\tau |
||
The logarithm to base 10 of e | M_LOG2E |
LOG2_E |
\log_{2}{e} |
|
The logarithm to base 10 of e | M_LOG10E |
LOG10_E |
\log_{10}{e} |
|
The logarithm to base 2 of ten | LOG2_10 |
\log_{2}{10} |
||
The logarithm to base 10 of 2 | LOG10_2 |
\log_{10}{2} |
||
The natural logarithm of 2 | M_LN2 |
LN_2 |
\ln{2} |
|
The natural logarithm of 10 | M_LN10 |
LN_10 |
\ln{10} |
|
The square root of 2 | M_SQRT2 |
SQRT_2 |
\sqrt{2} |
Footnotes
-
Fundamental types - cppreference.com ↩
-
Numeric types - The Rust Reference ↩
-
Bit Twiddling Hacks - Sean Anderson ↩