51 nod 乘法逆元

简介:

http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1256

#include <iostream>

using namespace std;
typedef long long LL;
void exgcd(LL a, LL b, LL &x, LL &y)//扩展欧几里得算法
{
    if(b == 0)
    {
        x=1;
        y=0;
        return ;
    }
    exgcd(b, a%b, x, y);
    LL tmp=x;
    x=y;
    y=tmp - (a/b)*y;
}
int main()
{
    LL m,n,x,y;
    while(cin>>m>>n)
    {
        exgcd(m, n, x, y);
        while(x<0)//当x<0时还要转换为正数
            x+=n;
        cout<<x<<endl;
    }
    return 0;
}
目录
相关文章
|
12月前
|
C++
51nod 1241 特殊的排序 (双连通分量)
51nod 1241 特殊的排序 (双连通分量)
39 0
LeetCode 299. Bulls and Cows
你正在和你的朋友玩 猜数字(Bulls and Cows)游戏:你写下一个数字让你的朋友猜。每次他猜测后,你给他一个提示,告诉他有多少位数字和确切位置都猜对了(称为“Bulls”, 公牛),有多少位数字猜对了但是位置不对(称为“Cows”, 奶牛)。你的朋友将会根据提示继续猜,直到猜出秘密数字。 请写出一个根据秘密数字和朋友的猜测数返回提示的函数,用 A 表示公牛,用 B 表示奶牛。
64 0
LeetCode 299. Bulls and Cows
Ultra-Fast Mathematician
Ultra-Fast Mathematician
66 0
HDOJ 1004题 Let the Balloon Rise strcmp()函数
HDOJ 1004题 Let the Balloon Rise strcmp()函数
91 0
|
网络协议 Linux Shell
How to install Ultra Monkey LVS
I'm the resident Linux guru at my job -- a mid-sized local company with a decent sized IT department.
822 0
|
C++
[LeetCode] Bulls and Cows
This problem seems to be easy at the first glance, especially the problem gives a too much simpler example.
910 0