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 source generation only. Write /app/gpu/main.cu; compilation,
execution and verification are performed later in a separate verifier environment.
How you are scored
- 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. - GPU verification uses the backend selected for this run: an H100 attached to the separate verifier, or a remote H100 worker. Hidden inputs use a fresh random seed.
- Correctness: every hidden input (small edge cases plus the timing input) must pass. Your output must be identical to the CPU program's output (trailing whitespace ignored). Any mismatch, crash or timeout gives reward 0.
- GPU execution: a separate, untimed CUPTI check must observe completed GPU kernel activity on the hidden timing input. A CPU-only submission receives reward 0 even if 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). Your port and our GPU reference are each run on it
once to warm up and then 5 times, interleaved; the time is the wall clock of the whole process
(including CUDA initialisation, input parsing and output). When correct,
reward = min(2, t_reference / t_yours)using the medians. /app/inputs/holds public input examples for understanding the input format.