CINTA第二次作业

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的最后两个数位等于什么?
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值