Data Processing

Description

Chinachen is a football fanatic, and his favorite football club is Juventus fc. In order to buy a ticket of Juv, he finds a part-time job in Professor Qu's lab.

And now, Chinachen have received an arduous task —— Data Processing.

The data was made up with N positive integer (n1n2n3, … ), he may calculate the number  , you can assume  mod N =0. Because the number is too big to count, so P mod 1000003 is instead.

Chinachen is puzzled about it, and can't find a good method to finish the mission, so he asked you to help him.

Input

The first line of input is a T, indicating the test cases number.

There are two lines in each case. The first line of the case is an integer N, and N ≤ 40000. The next line include N integer numbers n1n2n3 … ( ni ≤ N ).

Output

For each test case, print a line containing the test case number ( beginning with 1) followed by the P mod 1000003.

Sample Input

2
3
1 1 3
4
1 2 1 4

Sample Output

Case 1:4
Case 2:6

这题只要用下快速幂和乘法逆元便可;

#include <stdio.h>
#define mod 1000003
int kuaisumi(int x,int y)
{
    long long sum=1,xx;
    xx=x;//xx可能会超int的范围故用xx代替
    while(y)
    {
        if(y%2!=0)
            sum*=xx;
        y/=2;
        xx=(xx%mod)*(xx%mod)%mod;
        sum=sum%mod;
    }
    return sum;
}

void exgcd(long long a,long long b,long long &x,long long &y)
{
    if(b==0)
    {
        x=1;
        y=0;
        return ;
    }
    exgcd(b,a%b,x,y);
    long long tt;
    tt=x%mod;
    x=y%mod;
    y=(tt-(a/b)*x)%mod;
}
int main()
{
    int t;
    scanf("%d",&t);
    int cas=0;
    while(t--)
    {
        int n;
        scanf("%d",&n);
        long long s=0;
        for(int i=1;i<=n;i++)
        {
            int mm;
            scanf("%d",&mm);
            s=(s+kuaisumi(2,mm))%mod;
        }
        long long x,y;
        exgcd(n,mod,x,y);
        while(x<0)//拓展欧几里得得到的x可能为负数
            x+=mod;
        s=s*x%mod;
        cas++;
        printf("Case %d:%lld\n",cas,s);
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值