← CSES Better

Sum Prime-Reachable Residues

ZIO · 2026 · Zonal Informatics Olympiad · P3

Open official problem ↗
Ask AI

Open a hint-first prompt in a new AI chat. Grok may ask you to confirm before sending.

Open Claude Desktop

number-theory · modular-arithmetic · prime-factorization

The organizer’s problem statement is available at the official source link.

residue wheel

Mark residues that contain a prime

A residue m is good when some prime p has p mod N=m; sum each good residue once.

State table
Prime pResidue mDecision
p mod Nmmark if a prime p has this residue
all m from 0 to N-1good residuessum m
  1. 1

    Make residue buckets

    Make one bucket for each remainder 0…N−1.
  2. 2

    Identify prime classes

    Use N’s supplied prime factorization to characterize prime-possible remainders.
  3. 3

    Sum valid remainders

    Sum the marked remainder values.
Tools
1
2
3
4
5
6
7
8
9
10
11
12
Draft saved locally
|12 lines, 156 chars

Run output

Run your code to see output.