//这题的意思就是:求一个最小的正整数x,使a乘以x对m的取余等于1对m的取余!
#include "iostream"
using namespace std;
int main()
{
int testcase, i, a, m;
bool flag;
cin >> testcase;
while (testcase--)
{
cin >> a >> m;
flag = false;
if (m == 1)
{
cout << 1 << endl;
continue;
}
else
{
for (i = 1; i <= m; i++)
{
if ((a * i % m) == 1)
{
cout << i << endl;
flag = true;
break;
}
}
if (!flag)
cout << "Not Exist" << endl;
}
}
}
zoj 3609 Modular Inverse
最新推荐文章于 2019-05-04 07:03:00 发布