poj 3844 Divisible Subsequences 组合数学

/*
参看http://blog.csdn.net/wsniyufang/article/details/6666169
*/
#include<stdio.h>  
#include<string.h>  
int f[1000005];  
__int64 ans;  
int main()  
{  
    int i,j,k,t,n,d;  
    scanf("%d",&t);  
    while(t--){  
        scanf("%d%d",&d,&n);  
        memset(f,0,sizeof(f));  
        int num=0; ans=0;  
        while(n--){  
            scanf("%d",&k);  
            num=(num+k)%d;  
            if(num==0) f[num]++;  
            ans+=f[num];  
            if(num!=0) f[num]++;  
        }  
        printf("%I64d\n",ans);  
    }  
    return 0;  
}  

你可能感兴趣的:(poj 3844 Divisible Subsequences 组合数学)