P is a prime number, so there are:
(1). A/B % P = (a % (B * p)/B) % P;
(2). A/B % P = A * (B ') % P where B' is the inverse element of B for P
Method 1: # include <stdio. h> int main () {int I, t, x, V = 1, n, m, ans; long P, A [51000], sum; scanf ("% d", & T); While (t -- & scanf ("% d", & N) {A [0] = 1; sum = 0; P = 1000003; p * = N; for (I = 1; I <= 40000; I ++) {A [I] = 2 * A [I-1]; if (A [I]> = p) A [I]-= P ;}for (I = 0; I <n; I ++) {scanf ("% d", & X); sum + = A [X]; If (sum> = P) sum-= P;} ans = sum/N; printf ("case % d: % d \ n", V ++, ANS) ;}} Method 2: # include <stdio. h> # inclu De <math. h> # define Nmax 1000003 # define nnum 40001int num [nnum], X, Y; int extend_gcd (int A, int B) {If (B = 0) {x = 1, y = 0; return a;} int d = extend_gcd (B, A % B); int Tx = x; X = y; y = TX-A/B * Y; return D;} void Init () {int I, Te; for (I = 0, TE = 1; I <nnum; I ++) {num [I] = tE; Te = tE * 2% Nmax ;}} int main () {# ifndef online_judgefreopen ("t.txt", "r ", stdin); # endifint t, n, I, J, K; long res; Init (); While (scanf ("% d", & T )! = EOF) {for (I = 1; I <= T; I ++) {scanf ("% d", & N); For (j = 0, res = 0; j <n; j ++) {scanf ("% d", & K); Res + = num [k]; If (RES> = Nmax) {res-= Nmax ;}} extend_gcd (n, Nmax); X = (X % Nmax + Nmax) % Nmax; Res = res * x % Nmax; printf ("case % d: % i64d \ n", I, Res) ;}} return 0 ;}