HDU 3049 Data Processing

Data Processing

Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 530Accepted Submission(s): 191


Problem 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 (n1, n2, n3, … ), 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 n1,n2,n3… (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
Hint
Hint: You may use “scanf” to input the data.

Source
这个题比较水。直接二分幂,然后分母求逆元就可以了
我的代码:
#include<stdio.h> #include<string.h> typedef __int64 ll; ll num[40005]; ll mod=1000003; ll power(ll p,ll n,ll m) { ll sq=1; while(n) { if(n%2==1) sq=(sq%m)*(p%m)%m; p=(p%m)*(p%m)%m; n=n/2; } return sq%m; } int main() { int t,T,i; ll re,n,ans; scanf("%d",&T); for(t=1;t<=T;t++) { scanf("%I64d",&n); for(i=1;i<=n;i++) scanf("%I64d",&num[i]); re=power(n,mod-2,mod); ans=0; for(i=1;i<=n;i++) ans=(ans+power(2,num[i],mod))%mod; ans=ans*re%mod; printf("Case %d:%I64d\n",t,ans); } return 0; }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值