首页 技术 正文
技术 2022年11月20日
0 收藏 780 点赞 4,395 浏览 683 个字

题意:给出n=A mod 9973和B,求(A/B) mod 9973

昨天用扩展欧几里得做过这题,其实用逆元也可以做。

逆元的定义:例如a*b≡1 (mod m),则b就是a关于m的逆元。

求逆元方法也很简单,用扩展欧几里得解这个方程即可。

逆元性质:若a是b的逆元,则(x/a)mod p=(x*b)mod p

对于本题呢?设B的逆元为x,

那么有(A/B) mod 9973=((A mod 9973)*(x mod 9973))mod 9973

Reference:  http://blog.csdn.net/leonharetd/article/details/13095191

 #include <iostream>
using namespace std;
__int64 a,b,b1,x,k,tm,r,T,n,ans; __int64 extend_gcd(__int64 a,__int64 b,__int64 &x,__int64 &y)
{
if (b==)
{
x=;
y=;
return a;
}
else
{
__int64 r=extend_gcd(b,a%b,y,x);
y=y-x*(a/b);
return r;
}
} int gcd(int a,int b)
{
if (b==) return a;
return gcd(b,a%b);
} int main()
{
cin>>T;
while (T--)
{
cin>>n>>b;
//bx==1 (mod m)
tm=extend_gcd(b,,x,k);
b1=x*(/tm);
r=/tm;
b1=(b1%r+r)%r; //求出最小非负整数解
ans=(n*(b1%))%;
cout<<ans<<endl; }
return ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,992
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,506
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,349
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,134
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,767
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,844