Sunday, April 10, 2011

10489 - Boxes of Chocolates


#include<stdio.h>
int main ()
{
    long T,N,B,k,a,R,S;
    //freopen("in.txt","r",stdin);
    scanf("%ld",&T);

    while(T--)
    {
        scanf("%ld%ld",&N,&B);
        S=0;
        while(B--)
        {
            R=1;
            scanf("%ld",&k);
            while(k--)
            {
                scanf("%ld",&a);
                R=(R*a)%N;
            }
            S=(S+R)%N;
        }
        printf("%ld\n",S);
    }
    return 0;
}

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.