Statistical report · generated 2026-11-15 00:51 UTC

Modular arithmetic on Codeforces: 1e9+7, 998244353 and the long tail

This report covers 10,044 problems with full statements, which is 87.2% of the 11,520-problem Codeforces archive. Statements cover contests from 2010 to February 2025. The interactive dashboard has the same data with filters.

1. Executive summary

Problems analyzed
10,044
87.2% of the archive
Use modular arithmetic
993
9.9% of analyzed problems
1e9+7
479
48.2% of modular problems
998244353
347
34.9% of modular problems
Crossover year
2019
998244353 leads every year since

About one Codeforces problem in ten (9.9%) asks for its answer modulo something. Two moduli cover 83% of those problems. The older one, 1e9+7, was effectively the only big choice until 2017. 998244353 replaced it as the most common modulus from 2019 and now accounts for roughly two thirds of new big-two usage. A further 116 problems take the modulus as input, and 24 other fixed moduli each appear only a handful of times.

2. Data collection methodology

2.1 Sources

2.2 Storage, resumability and data quality

Everything is stored in one SQLite database with these tables: contests, problems, statements, detections, features, validation and crawl_state. API responses are written atomically through .part files. Dataset shards are downloaded with HTTP range-resume, and each shard is marked done in crawl_state once imported, so an interrupted run continues where it stopped. All writes are upserts keyed by (contest id, index), so re-runs refresh rows instead of duplicating them. Malformed records (missing ids or indices, non-numeric contest ids) are skipped. Duplicate API rows are dropped. Problems shared between a Div. 1 and Div. 2 round appear once in the API archive and are counted once.

2.3 Detecting moduli

  1. Normalization. LaTeX delimiters ($$$), thin and non-breaking spaces (\,, ~), digit-group separators (998\,244\,353, 998,244,353, 1 000 000 007), \cdot/\times, \bmod/\pmod, braces in exponents and unicode superscripts are all rewritten to plain arithmetic.
  2. Exact evaluation. Every expression governed by a modulus phrase ("modulo X", "remainder … divided by X", "mod (X)", "% (X)", "Let M = X") is evaluated exactly. 1e9+7, 10^9+7, 10^{9}+7, 1000000007 and 1 000 000 007 all become 1000000007, and 119·2^23+1 becomes 998244353.
  3. Flattened superscripts. Older statements in the dataset lost their superscripts, so 109+7 reads "109 + 7". Inside a modulus phrase only, "10k ± c" is re-read as 10k ± c, because a literal modulus of 116 is never intended.
  4. False-positive guards. Values below 1000 (parity, "mod 3", digit sums) are excluded. Results such as (x) mod M = 998244345 are not treated as moduli. Variable definitions only count for the letter actually used after "mod". Matches found only in sample notes, or not about the answer and neither prime nor a power of two (e.g. "2024 mod 1000"), are downgraded to uncertain. Divisibility (y mod x = 0), cyclic indexing ((i mod n) + 1) and "x mod y denotes" definitions are ignored.
  5. Automatic discovery. Any value meeting these rules counts as a modulus, which is how the 24 long-tail moduli were found. Prime moduli with at least 3 confirmed uses (998244353 (348), 1e6+3 (9), 1e9+9 (12), 1e9+7 (476)) are also searched for as bare numbers. A bare match only marks a problem uncertain, never confirmed.
Status of each problem: confirmed means a numeric modulus is stated as a requirement. Variable means the modulus is an input (e.g. "print it modulo p", or "3 ≤ p ≤ 109+9, p is prime"). Uncertain means a frequent modulus appears with no modulo phrase. None means no modulus. Headline statistics count confirmed + variable problems. Uncertain problems (15) are listed in §9 and can be included from the dashboard.

3. Coverage

The API archive holds 11,520 problems. Statements were available for 10,044 (87.2%). Of the 1,476 problems without a statement, 1,343 come from contests after the dataset snapshot (February 2025). The remainder are mostly special, interactive-only or unlisted problems. Status counts over the whole archive: confirmed 877, variable 116, uncertain 15, none 9,036, no statement 1,476.

4. Overall frequency and ranking

Figure 1. The 12 most-used fixed moduli (number of problems where the modulus is confirmed). Color follows the modulus: blue 1e9+7, orange 998244353, green others.

877 problems state a fixed modulus and 116 take a variable one. In total, 26 distinct fixed moduli were found. Only 2 problems state two different fixed moduli, and none states more than two. The full ranking:

#ModulusProblems% of modular problems% of analyzed problems
11e9+747948.24%4.77%
299824435334734.94%3.45%
31e9+9121.21%0.12%
41e6+380.81%0.08%
51e940.40%0.04%
62^3030.30%0.03%
72^3230.30%0.03%
85112398720.20%0.02%
92^1520.20%0.02%
1077777777720.20%0.02%
111e4+720.20%0.02%
121234510.10%0.01%
131e810.10%0.01%
141e3+1310.10%0.01%
15734003310.10%0.01%
169554272110.10%0.01%
17105113110.10%0.01%
181e3+910.10%0.01%
192^6410.10%0.01%
2049001910.10%0.01%
212^5810.10%0.01%
2299824485310.10%0.01%
23123456789110.10%0.01%
243160710.10%0.01%
2599999989310.10%0.01%
262024040110.10%0.01%

5. Difficulty

Figure 2. Heatmap: % of problems in each rating band that use each modulus. Darker cells mean a higher share.
Figure 3. 998244353's share of big-two problems in each rating band.
Rating bandProblemsModular1e9+7998244353Other fixedVariable998244353 share of big two
Unrated2275.29%2.20% (5)1.76% (4)0.88% (2)0.44% (1)44%
<12001,9920.95%0.35% (7)0.05% (1)0.00% (0)0.55% (11)12%
1200-15991,6793.39%1.73% (29)0.66% (11)0.42% (7)0.60% (10)28%
1600-19991,8877.21%4.08% (77)1.96% (37)0.21% (4)0.95% (18)32%
2000-23991,64814.32%8.07% (133)4.31% (71)0.73% (12)1.21% (20)35%
2400-27991,36519.56%8.28% (113)8.13% (111)1.25% (17)1.90% (26)50%
2800+1,24621.35%9.07% (113)8.99% (112)0.88% (11)2.41% (30)50%

The modular share rises almost monotonically with rating. Problems that use a modulus average 2340 (1e9+7), 2550 (998244353), 2347 (other fixed) and 2244 (variable), against 1798 for problems without one. 998244353 is the modulus of hard problems, while low-rated counting problems still mostly default to 1e9+7.

6. Contest type and time

Figure 4. Modular usage by contest type (types with at least 20 problems), as % of that type's problems.
Contest typeProblemsModular1e9+7998244353Other fixedVariable998244353 share of big two
Div. 23,2827.59%4.97% (163)1.34% (44)0.27% (9)1.01% (33)21%
Div. 11,70516.13%8.62% (147)4.34% (74)1.17% (20)1.99% (34)33%
Educational1,14111.48%2.89% (33)7.89% (90)0.35% (4)0.35% (4)73%
Olympiad / Mirror / Company1,1339.97%4.59% (52)3.80% (43)0.88% (10)0.71% (8)45%
Other8767.53%3.08% (27)2.51% (22)0.68% (6)1.26% (11)45%
Div. 38633.71%1.62% (14)1.27% (11)0.00% (0)0.81% (7)44%
Div. 1 + Div. 252916.64%6.05% (32)7.18% (38)0.57% (3)2.84% (15)54%
Global24613.41%2.44% (6)9.76% (24)0.00% (0)1.22% (3)80%
Div. 41732.31%1.73% (3)0.58% (1)0.00% (0)0.00% (0)25%
April Fools962.08%0.00% (0)0.00% (0)1.04% (1)1.04% (1)–
Figure 5. % of each year's problems using each modulus. 2025 is partial and drawn dashed: the statement dataset ends in February 2025.
Figure 6. The same series as raw problem counts.
Figure 7. 998244353's share of the big two by year.
YearProblemsModular1e9+7998244353Other fixedVariable998244353 share of big two
20102712.21%0.37% (1)0.00% (0)1.48% (4)0.37% (1)0%
20113955.57%2.53% (10)0.00% (0)2.03% (8)1.01% (4)0%
20125237.27%5.16% (27)0.00% (0)1.34% (7)0.76% (4)0%
20134859.28%7.01% (34)0.00% (0)1.86% (9)0.41% (2)0%
201447911.06%9.19% (44)0.21% (1)0.42% (2)1.25% (6)2%
20154418.39%6.58% (29)0.00% (0)0.68% (3)1.13% (5)0%
20166057.27%5.62% (34)0.17% (1)0.83% (5)0.66% (4)3%
201767110.88%8.35% (56)0.60% (4)0.30% (2)1.64% (11)7%
201884010.24%4.17% (35)3.93% (33)0.60% (5)1.55% (13)49%
201994710.56%4.65% (44)4.86% (46)0.32% (3)0.74% (7)51%
20209368.44%3.31% (31)4.27% (40)0.11% (1)0.75% (7)56%
202181712.85%5.02% (41)5.88% (48)0.12% (1)1.84% (15)54%
202284311.15%3.08% (26)6.17% (52)0.12% (1)1.78% (15)67%
202384111.77%3.45% (29)7.25% (61)0.00% (0)1.07% (9)68%
202486911.74%3.68% (32)6.33% (55)0.23% (2)1.50% (13)63%
20258112.35%4.94% (4)7.41% (6)0.00% (0)0.00% (0)60%

By calendar month

Month-of-year has no meaningful effect. Monthly modular shares range from 8.5% to 12.1%, which is within noise for roughly 700–960 problems per month.

MonthProblemsModular998244353 share
Jan70611.5%40%
Feb8319.5%40%
Mar8858.6%43%
Apr9289.5%36%
May7788.9%43%
Jun8398.5%25%
Jul8169.6%46%
Aug6989.3%31%
Sep84811.7%38%
Oct9659.8%37%
Nov8189.7%48%
Dec93212.1%66%

7. Problem tags

Figure 8. Modular usage within selected tags (% of each tag's problems), stacked by modulus.
TagProblemsModularLift vs archive1e9+7998244353Other fixedVariable998244353 share
fft9573.7%7.45×8514786%
combinatorics70469.0%6.98×222218103650%
matrices12753.5%5.42×39166729%
probabilities22932.8%3.31×29422259%
dp2,20324.5%2.48×269211184244%
number theory77421.1%2.13×7342103837%
math2,99918.7%1.90×257214226945%
divide and conquer30317.8%1.80×16282864%
bitmasks59314.0%1.42×47292538%
trees83912.8%1.29×51453847%
hashing2219.5%0.96×1270237%
graphs1,0888.7%0.88×48355742%
data structures1,8147.9%0.80×625591847%
games2437.8%0.79×5102267%
brute force1,7755.9%0.59×384351853%
strings7445.5%0.56×2992124%
geometry3913.8%0.39×851138%
implementation2,8073.7%0.37×543061336%
constructive algorithms1,7953.0%0.30×181911551%
greedy3,0092.6%0.26×312841447%

Lift is the tag's modular rate divided by the archive rate (9.9%). The most common tag combinations among problems using each modulus:

ModulusTop tag pairsTop tag triples
1e9+7combinatorics + math (141); combinatorics + dp (134); dp + math (121); math + number theory (60); combinatorics + number theory (37)combinatorics + dp + math (78); combinatorics + math + number theory (27); dp + math + number theory (24)
998244353combinatorics + math (149); combinatorics + dp (136); dp + math (132); fft + math (42); math + number theory (37)combinatorics + dp + math (97); combinatorics + fft + math (28); combinatorics + math + number theory (25)
Other fixedmath + number theory (8); combinatorics + dp (5); math + matrices (4); combinatorics + math (4); dp + math (4)combinatorics + dp + math (3); data structures + divide and conquer + graphs (2); combinatorics + dp + number theory (2)
Variablemath + number theory (30); combinatorics + dp (26); combinatorics + math (22); dp + math (20); brute force + math (12)combinatorics + dp + math (14); brute force + math + number theory (8); combinatorics + math + number theory (6)

number theory problems use moduli at 21.1% and lean towards 1e9+7 (63% of big-two usage), as do strings (76%), where hashing traditionally uses 1e9+7-style primes.

8. Other dimensions

8.1 Problem index

Figure 9. Modular usage by problem index (letters with at least 30 problems).
IndexProblemsModular1e9+7998244353Other fixedVariable998244353 share of big two
A1,8071.66%0.72% (13)0.11% (2)0.17% (3)0.66% (12)13%
B1,7903.80%2.23% (40)0.50% (9)0.17% (3)0.89% (16)18%
C1,5328.75%4.96% (76)2.15% (33)0.59% (9)1.04% (16)30%
D1,53711.91%6.57% (101)3.32% (51)0.78% (12)1.24% (19)34%
E1,52116.90%8.74% (133)5.46% (83)1.12% (17)1.58% (24)38%
F95817.64%6.78% (65)8.66% (83)0.42% (4)1.77% (17)56%
G46118.44%7.81% (36)8.68% (40)0.87% (4)1.08% (5)53%
H20421.57%3.92% (8)14.22% (29)0.49% (1)2.94% (6)78%
I9214.13%1.09% (1)11.96% (11)0.00% (0)1.09% (1)92%
J458.89%2.22% (1)6.67% (3)0.00% (0)0.00% (0)75%

8.2 Time and memory limits, test counts

Figure 10. Modular usage by time-limit band.
Figure 11. Modular usage by memory-limit band.
GroupProblemsMean TL (s)Median TL (s)Mean ML (MB)Median ML (MB)Median system testsMean rating
1e9+74772.372303256452340
9982443533473.112394256382550
Other fixed533.213293256422347
Variable1162.672364256402244
None9,0472.032294256401798

Multi-test input format: 6.9% of multi-test problems and 11.2% of single-test problems use a modulus. The number of system tests barely differs between groups (median 38–45).

8.3 Explicit vs. introduced in the solution

Nearly every modulus is explicit in the statement. Only 5 of 6,078 problems with an editorial use a modulus that appears only in the editorial (2520, 987898789, 2^64, 2020, 2^30). These are typically hashing moduli or bounds such as 264, and editorials rarely restate the hashing modulus, so this figure is a lower bound.

8.4 What the modular operations are

Statement signals are measured over all problems in the group. Editorial signals are measured over problems that have an editorial (1e9+7: 264, 998244353: 286, other: 13, variable: 73).

Operation / signal1e9+7998244353Other fixedVariable
counting56%58%42%34%
probability / expectation10%16%6%1%
modular inverse (p/q answer)9%15%8%1%
sum over objects5%6%6%5%
binomial coefficients31%46%15%21%
factorials5%12%0%4%
modular inverse7%8%23%5%
fast exponentiation4%4%15%4%
FFT / NTT2%11%8%5%
matrix exponentiation4%2%0%1%
inclusion-exclusion5%8%8%1%
CRT / Lucas0%0%8%5%
hashing0%2%0%1%

9. Trends, correlations and unexpected findings

Unexpected

10. Validation

A stratified random sample of 110 problems (40 confirmed, 15 uncertain, 15 variable, 40 none, with half of the "none" sample drawn from problems whose text mentions modulo or remainder) was read and judged by hand. The sample is selected by a seeded hash, so it can be reproduced (validate.py). Every verdict is in validation.csv.

Predicted statusSampledCorrectPartialWrong
confirmed404000
variable151401
uncertain151140
none404000

Overall: 105/110 correct, 4 partial, 1 wrong. Precision on the 40 sampled confirmed problems was 40/40. A dedicated recall check, which searched every statement for 998244353 / 1e9+7 in any notation, found no remaining confirmed misses beyond intentional exclusions such as constraints, jokes and examples. Errors and partial cases:

Uncertain problems (excluded from headline counts): 792F (1e6+1), 991F (1e9+7), 1096A (998244353), 1096C (998244353), 1096D (998244353), 1165A (1e5), 1192B (2000), 1295A (998244353), 1355F (998244353), 1560F1 (998244353), 1560F2 (998244353), 1599F (1e9+7), 1614E (1e9+1), 1844C (998244353), 1933D (1e3).

11. Limitations and possible biases

12. Reproducibility

python3 -m venv .venv && .venv/bin/pip install pyarrow   # only the crawler needs pyarrow
.venv/bin/python crawler.py      # API + dataset into SQLite (cached, resumable, incremental)
python3 detect.py                # modulus detection
python3 validate.py sample       # reproduce the validation sample; validate.py load imports verdicts
python3 analyze.py               # aggregates + exports
python3 build.py                 # site + report + PDF

Scripts: source.zip. Statement text © the problem authors / Codeforces, via open-r1/codeforces (CC BY 4.0). The published data files contain metadata and short detection snippets only.