首页 > OPPO 8.29笔试模1数
头像
proxys
编辑于 2020-08-29 21:07
+ 关注

OPPO 8.29笔试模1数

这道题涉及到一个密码学中学到的方法
设置以下矩阵:
a b
1 0
0 1
然后将a,b使用矩阵运算(列运算)化为0 1 或者1 0,其中1下面的那个就是结果
#include <iostream>
#include <vector>
using namespace std;
int main()
{
    int a, b;
    cin >> a >> b;
    vector<int> temp1{ a,1,0 };
    vector<int> temp2{ b,0,1 };
    bool mods = false;
    while (!((temp1[0] == 0 && temp2[0] == 1) || (temp2[0] == 0 && temp1[0] == 1)))
    {
        if (mods)
        {
            int t = temp1[0] / temp2[0];
            for (int j = 0; j < 3; j++)
            {
                temp1[j] = temp1[j] - temp2[j] * t;
            }
        }
        else
        {
            int t = temp2[0] / temp1[0];
            for (int j = 0; j < 3; j++)
            {
                temp2[j] = temp2[j] - temp1[j] * t;
            }
        }
        mods = !mods;
    }
    if (temp1[0] == 1)
    {
        int t = temp1[1];
        if (t < 0)
            t = t + b;
        cout << t;

    }
    else
    {
        int t = temp2[1];
        if (t < 0)
            t = t + b;
        cout << t;
    }
    return 0;
}


全部评论

(0) 回帖
加载中...
话题 回帖

推荐话题

相关热帖

近期热帖

历年真题 真题热练榜 24小时
技术(软件)/信息技术类
查看全部

近期精华帖

热门推荐