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;
}


#笔试题目##OPPO#
全部评论

相关推荐

05-11 20:45
门头沟学院 Java
有担当的灰太狼又在摸...:零帧起手查看图片
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务