给出2个数M和N(M < N),且M与N互质,找出一个数K满足0 < K < N且K * M % N = 1,如果有多个满足条件的,输出最小的. Solution 用 EXGCD 求解逆元,可以适用于一切 \((M,N)=1\) 的情况 #include <bits/stdc++.h> using namespace std; #define int long long inline void exgcd(int a,int b,int &x,int &y)…
题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1256 给出2个数M和N(M < N),且M与N互质,找出一个数K满足0 < K < N且K * M % N = 1,如果有多个满足条件的,输出最小的. Input 输入2个数M, N中间用空格分隔(1 <= M < N <= 10^9) Output 输出一个数K,满足0 < K < N且K * M % N = 1,…
基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 给出2个数M和N(M < N),且M与N互质,找出一个数K满足0 < K < N且K * M % N = 1,如果有多个满足条件的,输出最小的.Input输入2个数M, N中间用空格分隔(1 <= M < N <= 10^9)Output输出一个数K,满足0 < K < N且K * M % N = 1,如果有多个满足条件的,输出最小的.Input示例2 3Output示例2 思路:…
1256 乘法逆元 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 收藏 关注给出2个数M和N(M < N),且M与N互质,找出一个数K满足0 < K < N且K * M % N = 1,如果有多个满足条件的,输出最小的.Input输入2个数M, N中间用空格分隔(1 <= M < N <= 10^9)OutPut输出一个数K,满足0 < K < N且K * M % N = 1,如果有多个满足条件的,输出最小的.Input示例2…
题目链接: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1256 题意:中文题诶~ 思路: M, N 互质, 求满足 K * M % N = 1 的最小k, 由这个式子我们可以得到y*N+1=k*M, 我们将这个式子变化一下, k*M+y'*N=1, 求最小的k, 就是求最小乘法逆元啦~ 解这个式子我们直接用exgcd()就好啦~ 代码: #include <bits/stdc++.h> using namespa…
The modular modular multiplicative inverse of an integer a modulo m is an integer x such that a-1≡x (mod m). This is equivalent to ax≡1 (mod m). Input There are multiple test cases. The first line of input is an integer T ≍ 2000 indicating the number…
A. On The Way to Lucky Plaza time limit per test 1.0 s memory limit per test 256 MB input standard input output standard output Alaa is on her last day in Singapore, she wants to buy some presents to her family and friends. Alaa knows that the best p…