Representation numbers of mixed-power diagonal forms
/app/cpu/main.cpp is the source of a multicore CPU program (C++17, OpenMP).
The program takes one input-file path (PROGRAM INPUT_FILE) and writes its result to stdout.
What the program computes
For each query (a diagonal Diophantine form with mixed powers) it computes the representation numbers
r(n) = #{ (t_1, ..., t_T) : c_1*t_1^p_1 + c_2*t_2^p_2 + ... + c_T*t_T^p_T = n } for 0 <= n < N
where variable t_j ranges over all integers if term j is signed (s_j = 1, only for
even p_j) and over non-negative integers otherwise. Counts are kept modulo 2^64.
The CPU program starts from r = delta_0 and applies the terms one after another as sparse
convolutions: with the shifts c_j*t^p_j < N (t = 0, 1, 2, ...) and weights 2 for t > 0
of a signed term, else 1, r'(n) = sum_t weight(t) * r(n - c_j*t^p_j). It is blocked over n.
Input format
Q
N T
c_1 p_1 s_1
...
c_T p_T s_T
(repeated Q times)
1 <= N <= 5,000,000, 1 <= T <= 8, 1 <= c <= 1000, 2 <= p <= 6, s in {0, 1} and
s = 1 only for even p.
Output format
Three lines per query, in input order:
N TOTAL ZEROS HASH LASTZERO
max MAXR ARGMAX
tail r(N-1) r(N-2) ... r(N-8)
TOTAL: sum ofr(n)(mod 2^64);ZEROS: number ofnwithr(n) = 0;LASTZERO: the largest suchn(-1if none).HASH: sum overnwithr(n) != 0ofmix64((n << 1) xor mix64(r(n)))modulo 2^64 (mix64= SplitMix64 finaliser in the CPU source).MAXR: the largestr(n)(as unsigned 64-bit),ARGMAXthe smallestnattaining it (-1if all zero).tail: the lastmin(N, 8)values, starting fromr(N-1)downwards.
Hidden inputs
Correctness inputs include N = 1, terms with no admissible shift except t = 0, random
forms with 1 to 8 terms and powers 2..6 for N up to 10^6, and
one 8-term form with N = 5,000,000. The timing input has 32 forms with N in [3e6, 4e6],
each with four square terms (one with c = 1, three with c in [2, 6]), one cube term and one
fourth-power term (c in [1, 10]), in random order.
Your task
Port this program to CUDA in /app/gpu/main.cu: same command line (PROGRAM INPUT_FILE),
same output on stdout. Then make it as fast as you can on the GPU while keeping the output correct.
The main computation must execute on the GPU. Renaming CPU code to .cu, running a
CPU fallback, or launching a dummy kernel while computing the answer on the CPU does not satisfy this task.
The CPU source is the specification: when this text and the code disagree, the code wins.
This sandbox is for writing the source only: it has g++ and the CPU program, but no CUDA
compiler and no GPU. Compilation, execution and verification happen later on an H100 in a
separate verifier, and a port that does not compile is rejected, so check your logic against
the CPU program before you finish (for example by emulating your kernels on the host).
How your port is verified
- Only
/app/gpu/main.cuis collected. It is compiled withnvcc -O3 -arch=sm_90 -std=c++17 -o port /app/gpu/main.cu; no extra libraries are linked. The CUDA runtime and the header-only libraries that ship with the CUDA toolkit (CUB, Thrust, libcu++) are allowed. - Your source must not contain any of:
system(,popen(,fork(,exec*,dlopen(,getenv(,#include <filesystem>,/tests/,/proc/. The program may read only the input file it is given. - Verification runs on one H100 in a fresh container without network. Hidden inputs are generated with a fresh random seed at verification time.
- Correctness: every hidden input (small edge cases plus a large timing input) must pass. Your output must be identical to the CPU program's output (trailing whitespace ignored). Any mismatch, crash or timeout is rejected.
- GPU execution is checked: a port that computes its answer on the CPU is rejected even when its output is correct.
- Speed: The timing input has 32 forms, each with N in [3e6, 4e6] and six terms (four squares, one cube, one fourth power).
/app/inputs/timing_example.inhas the shape and size of the hidden timing input. Your port is timed against a reference GPU port on it; the faster your port, the higher its score. /app/inputs/holds public input examples for understanding the input format.