hdu 3049 Data Processing(扩展欧几里德求逆元)
来源:互联网 发布:安卓手机数据恢复系统 编辑:程序博客网 时间:2024/06/03 11:17
Data Processing
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 980 Accepted Submission(s): 297
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.题意:求A/B%P的值。思路:利用P是素数所以有:
(1). A/B%P=((A%(B*P))/B)%p;
(2). A/B%P=A*(B`)%P 其中B`是B对于P的逆元
方法一: #include<stdio.h>int main() { int i, t, x, v = 1, n, m, ans; long long P, a[51000], sum; scanf("%d", &t); while (t-- && scanf("%d", &n)) { a[0] = 1; sum = 0; P = 1000003; P *= n; for (i = 1; i <= 40000; i++) { a[i] = 2 * a[i - 1]; if (a[i] >= P) a[i] -= P; } for (i = 0; i < n; i++) { scanf("%d", &x); sum += a[x]; if (sum >= P) sum -= P; } ans = sum / n; printf("Case %d:%d\n", v++, ans); }} 方法二: #include<stdio.h>#include<math.h>#define nmax 1000003#define nnum 40001int num[nnum], x, y;int extend_gcd(int a, int b) { if (b == 0) { x = 1, y = 0; return a; } int d = extend_gcd(b, a % b); int tx = x; x = y; y = tx - a / b * y; return d;}void init() { int i, te; for (i = 0, te = 1; i < nnum; i++) { num[i] = te; te = te * 2 % nmax; }}int main() {#ifndef ONLINE_JUDGE freopen("t.txt", "r", stdin);#endif int t, n, i, j, k; long long res; init(); while (scanf("%d", &t) != EOF) { for (i = 1; i <= t; i++) { scanf("%d", &n); for (j = 0, res = 0; j < n; j++) { scanf("%d", &k); res += num[k]; if (res >= nmax) { res -= nmax; } } extend_gcd(n, nmax); x = (x % nmax + nmax) % nmax; res = res * x % nmax; printf("Case %d:%I64d\n", i, res); } } return 0;}
- hdu 3049 Data Processing(扩展欧几里德求逆元)
- hdu 3049 Data Processing(扩展欧几里德求逆模)
- HDU 3049 Data Processing
- hdu 3049 Data Processing
- hdu 3049 Data Processing
- HDU 3049 Data Processing 数论题解
- HDU 1222 欧几里德公式扩展
- hdu 2669 Romantic 扩展欧几里德
- HDU 2669 Romantic(扩展欧几里德)
- HDU 5512 Pagodas (扩展欧几里德)
- 扩展欧几里德求逆元模版
- 扩展欧几里德求逆元
- 扩展欧几里德求逆元模板
- 扩展欧几里德求逆元
- 扩展欧几里德,求逆元模板
- HDU 3049 Data Processing(a/b mod c, 逆元)
- hdu - 3049 - Data Processing(乘法逆元)
- HDU 1576 A/B 扩展欧几里德算法
- hdu 1712 ACboy needs your help (分组背包)
- 【树形DP】 HDU 4118 Holiday's Accommodation
- 跟我学ios 开发 (一)
- 已知有个rand7()的函数,返回1到7随机自然数,让利用这个rand7()构造rand10()
- HDU1233 还是畅通工程 解题报告--prim
- hdu 3049 Data Processing(扩展欧几里德求逆元)
- poj3181(完全背包)
- win7用户文件夹转移到D盘
- Cocos2d-iphone 为sprite添加双击的事件响应
- WIN7 CDC类 虚拟串口驱动无法安装的解决办法
- hadoop命令(仅供自己查看使用)
- HDU1863 畅通工程 解题报告--prim
- linux挂载新硬盘,开机自动挂载
- PhantomReference的个人理解