templates/int128-io.cpp
compilable
$cat templates/int128-io
128-bit Integer I/O
Read and print __int128 values — a GCC extension for 128-bit signed integers not supported by standard cin/cout.
#int128#io#gcc-extension#large-numbers
Log in to track progress, save custom versions, and organize into collections.Log In
$cat source_code/
cpp
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <bits/stdc++.h>
using namespace std;
__int128 read128() {
__int128 x = 0;
int f = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') f = -1;
ch = getchar();
}
while (isdigit(ch)) {
x = x * 10 + (ch - '0');
ch = getchar();
}
return x * f;
}
void print128(__int128 x) {
if (x < 0) { putchar('-'); x = -x; }
if (x > 9) print128(x / 10);
putchar(x % 10 + '0');
}23 linesutf-8
$cat explanation_notes.md
notes_viewer --renderedmarkdown (math enabled)
128-bit Integer I/O
GCC provides __int128 for 128-bit signed integers (range ), but cin/cout/scanf/printf don't support it. These functions handle I/O manually.
How It Works
getchar(), handles negative sign, accumulates digits into __int128putchar()When to Use
long long range (e.g., )Complexity
Notes
__int128 only for intermediate calculations and convert to long long for I/O