CINTA第二次作业
编程题
1.写一个模指数运算函数Mod_ExP,输入日、b和m,输出a^b modm,即a的b次方模m。
#include <iostream>
#include <stdio.h>
using namespace std;
typedef long long LL;
LL a, b, m;
LL Mod_Exp(LL a, LL b)
{
LL ans = 1 % m;
while (b)
{
if (b & 1)
{
ans = ans * a % m;
}
b >>= 1;
a = a * a % m;
}
return ans;
}
signed main()
{
cin >> a >> b >> m;
LL t = Mod_Exp(a, b);
cout << t << endl;
}
2.写一个求乘法逆元的函数Mul_Inverse, 输入a和m,求a模m的乘法逆元。提示,要求只输出正整数。
#include<iostream>
using namespace std;
int main()
{
int Mul_Inverse(int a, int b);
int a, m;
cout << "请输入a和m\n";
cin >> a >> m;
cout << "a模m的乘法逆元";
if (Mul_Inverse(a, m) < 0) cout << "不存在!\n";
else cout << "为" << Mul_Inverse(a, m);
return 0;
}
int Mul_Inverse(int a, int b)
{
int r0 = 1, r1 = 0, s0 = 0, s1 = 1;
while (b)
{
int q = a / b;
int temp1 = a;
a = b; b = temp1 % b;
int temp2 = r0;
r0 = r1; r1 = temp2 - q * r1;
int temp3 = s0;
s0 = s1; s1 = temp3 - q * s1;
}
if (a == 1 && r0 > 0)
return r0;
else return -1;
}
计算题
1.设 p=23 和 a=3,使用费马小定理计算
a
2019
a^{2019}
a2019mod p?
5.请证明13整除
2
70
2^{70}
270+
3
70
3^{70}
370。【提示:这是一道名为证明题的计算题】
6.使用欧拉定理计算
2
100000
2^{100000}
2100000mod 55。
8.手动计算
7
1000
7^{1000}
71000的最后两个数位等于什么?