hdu 3049 Data Processing(扩展欧几里德求逆模)
来源:互联网 发布:软件 地图周围距离 编辑:程序博客网 时间:2024/06/01 10:25
Data Processing
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1066 Accepted Submission(s): 324
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.
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).
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
231 1 341 2 1 4
Sample Output
Case 1:4Case 2:6HintHint: You may use “scanf” to input the data.
Source
2009 Multi-University Training Contest 14 - Host by ZJNU
Recommend
gaojie
题意:求那个等式的解...
题解:次方部分用快速幂,然后乘以b对于mod的逆模再取模,注意算出来的x有可能是负数...
#include<stdio.h>#define mod 1000003int pow(int x){ long long res=1,c=2; while(x) { if(x&1) res=(res*c)%mod; c=(c*c)%mod; x>>=1; } return res%mod;}void exgcd(int a,int b,int &d,int &x,int &y){ if(!b){ d=a; x=1; y=0; } else{ exgcd(b,a%b,d,y,x); y-=x*(a/b); }}int main(){ int t,i,d,x,y,n,cas=1; long long res; scanf("%d",&t); while(t--) { scanf("%d",&n); for(res=i=0;i<n;i++) { scanf("%d",&x); res=(res+pow(x))%mod; } exgcd(n,mod,d,x,y); printf("Case %d:%I64d\n",cas++,res*(x%mod+mod)%mod); } return 0;}
- hdu 3049 Data Processing(扩展欧几里德求逆模)
- hdu 3049 Data Processing(扩展欧几里德求逆元)
- HDU 3049 Data Processing
- hdu 3049 Data Processing
- hdu 3049 Data Processing
- HDU 2669 Romantic(扩展欧几里德)
- HDU 2669 Romantic(扩展欧几里德)
- 欧几里德和扩展(hdu 1222)
- HDU 2669 Romantic(扩展欧几里德)
- hdu - 3049 - Data Processing(乘法逆元)
- HDU 3049 Data Processing 数论题解
- HDU 1222 欧几里德公式扩展
- hdu 2669 Romantic 扩展欧几里德
- HDU 2669 Romantic(扩展欧几里德)
- HDU 5512 Pagodas (扩展欧几里德)
- (扩展)欧几里德算法
- (扩展)欧几里德
- (扩展)欧几里德算法
- eclipse 错误: 找不到或无法加载主类
- Fedora16下安装vsftpd实现ftp小结
- 总结curl,fsocket,pfsocket,stream_socket_client
- shell入门(1)
- js 在线客服
- hdu 3049 Data Processing(扩展欧几里德求逆模)
- 用kgdb 调试模块-第三部分:动态启动kgdb
- shell入门(2)
- oracle 10g 更换主机名或者IP后引起EM (dbconsole) 启动失败的解决方法
- Facebook Android SDK
- itoa 转换
- epoll_create, epoll_ctl和epoll_wait & select函数分析
- java 继承和多态 问题
- ora-12638 credential retrieval failed(身份证明检索失败)