用vc6.0的c语言程序写出求a=(m-xr)k⁻¹mod(p-1)=(5-8×6)×9mod10=3的过程
时间: 2024-02-01 07:13:46 浏览: 75
C语言编程,1-10的阶乘
首先,我们需要计算出p-1的值。
```
int p = 11; //假设p为11
int p_minus_1 = p - 1; //计算p-1的值
```
接下来,我们需要计算k的逆元。
```
int k = 9;
int k_inverse = 0;
for (int i = 1; i < p_minus_1; i++) {
if ((k * i) % p_minus_1 == 1) {
k_inverse = i;
break;
}
}
```
接着,我们可以计算出m-xr的值。
```
int m = 5;
int x = 6;
int r = 8;
int m_minus_xr = m - x * r;
```
最后,我们可以将(m-xr)k⁻¹ mod (p-1)的值计算出来。
```
int a = (m_minus_xr * k_inverse) % p_minus_1;
```
在本例中,a的值为3。
完整代码如下:
```
#include <stdio.h>
int main() {
int p = 11;
int p_minus_1 = p - 1;
int k = 9;
int k_inverse = 0;
for (int i = 1; i < p_minus_1; i++) {
if ((k * i) % p_minus_1 == 1) {
k_inverse = i;
break;
}
}
int m = 5;
int x = 6;
int r = 8;
int m_minus_xr = m - x * r;
int a = (m_minus_xr * k_inverse) % p_minus_1;
printf("a = %d\n", a);
return 0;
}
```
阅读全文