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;
} 
查看2道真题和解析