计算机数学第二次

第7题

矩阵刚开始

1  0  11

0  1  5

  变换一次后

0   1  5

1  -2  1

所以乘法逆元为-2

(2)

矩阵刚开始为

1 0 121

0 1 13

变换一次为

0 1 13

1 -9 4

变换两次为

1 -9 4

-3 28 1

所以乘法逆元为 28

(3)

矩阵刚开始为

1 0 1021

0 1 131

变换一次为

0 1 131

1 -7 104

变换两次为

1 -7 104

-1 8 27

变换三次为

-1 8 27

4  -31  23

变换四次为

4 -31 23

-5  39 4

变换5次为

-5  39  4

29  226 3

变换6次为

29 226 3

-34 -187  1

所以乘法逆元为187

第8题

#include <iostream> 
using namespace std;
int fun(int x,int y,int m)
{
    int z;
    if(y==0)
    {
        return 1;
    }
    z=fun(x,y/2,m);
    if((y%2)==0)//偶数
    return z*z%m;
    else
    return x*z*z%m; 
    
}
int main() 
{
    int x,y,m;
    cout<<"请输入模指数参数" <<endl;
    int p;//模指数结果 
    cin>>x>>y>>m;
    fun(x,y,m);
    cout<<"运算结果为"<<fun(x,y,m)<<endl;
    return 0;
}

第9题:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int d=10000;
struct s
{
    ll a[2][2];
};
s   mul(s x,s y)//矩阵乘法 
{
    s temp;
    memset(temp.a,0,sizeof(temp.a));//初始化 
    for(int i=0;i<2;i++)
        for(int j=0;j<2;j++)
        for(int k=0;k<2;k++)
        temp.a[i][j]=(temp.a[i][j]+x.a[i][k]*y.a[k][j])%d;//矩阵乘法 
    return temp;
}
void pow(int n)//矩阵幂 
{
    s c,res;
    c.a[0][0]=c.a[0][1]=c.a[1][0]=1;
    c.a[1][1]=0;//初始化 
    memset(res.a,0,sizeof(res.a));//初始化 
    for(int i=0;i<2;i++) res.a[i][i]=1;
    while(n)
    {
        if(n&1) res=mul(res,c);
        c=mul(c,c);
        n=n>>1;
    }
    printf("%I64d\n",res.a[0][1]);
}
int main()
{
    int n;
    cout<<"请输入位置,结束请输入-1"
    while(~scanf("%d",&n)&&n!=-1)
    {
        pow(n);
    }
    return 0;
}


第10题

反证法

假设存在两个不同的整数使得cc^-1-1=modm

cd-1=modm;

则根据定理的右边相减为0,左边相减也应该为0,左边为c(c^-1-d),c为正整数

然而d不等于c^-1,显然不可能实现所以假设错误

得证

第11题


def ext_gcd(c, m):    
    if m== 0:          
        return 1, 0, c    
    else:         
        x, y, gcd = ext_gcd(m, c % m)       
        x, y = y, (x - (c // m) * y) #辗转相除法反向推导        
        return x, y, gcd

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值