hdu 1576 A/B (求逆元)
每组数据有两个数n(0 <= n < 9973)和B(1 <= B <= 10^9)。
1000 53
87 123456789
6060
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#define LL __int64
const int maxn = 1e3 + ;
const int mo = ;
using namespace std; void exgcd(LL a, LL b, LL &d, LL &x, LL &y)
{
if(!b) {d = a; x = ; y = ;}
else{ exgcd(b, a%b, d, y, x); y -= x*(a/b); }
} LL mo_reve(LL a, LL n)
{
LL x, y;
LL d;
exgcd(a, n, d, x, y);
if(d==) return (x%n+n)%n;
else return -;
} int main()
{
int t, n, b;
scanf("%d", &t);
while(t--)
{
scanf("%d%d", &n, &b);
int x = mo_reve(b, mo);
printf("%d\n", n*x%mo);
}
return ;
}
hdu 1576 A/B (求逆元)的更多相关文章
- HDU 1576 A/B( 逆元水 )
链接:传送门 思路: 现在给出 n = A % 9973,n = A - A/9973×9973,已知 B|A ,设 A = Bx,可以得到如下形式的式子:Bx + 9973×y = n ,因为gcd ...
- hdu 1576 求逆元
题意:给出n=A mod 9973和B,求(A/B) mod 9973 昨天用扩展欧几里得做过这题,其实用逆元也可以做. 逆元的定义:例如a*b≡1 (mod m),则b就是a关于m的逆元. 求逆元方 ...
- 【hdu 1576】A/B(数论--拓展欧几里德 求逆元 模版题)
题意:给出 A%9973 和 B,求(A/B)%9973的值. 解法:拓展欧几里德求逆元.由于同余的性质只有在 * 和 + 的情况下一直成立,我们要把 /B 转化为 *B-1,也就是求逆元. 对于 B ...
- HDU 5768Lucky7(多校第四场)容斥+中国剩余定理(扩展欧几里德求逆元的)+快速乘法
地址:http://acm.hdu.edu.cn/showproblem.php?pid=5768 Lucky7 Time Limit: 2000/1000 MS (Java/Others) M ...
- hdu 1576 A/B 【扩展欧几里得】【逆元】
<题目链接> <转载于 >>> > A/B Problem Description 要求(A/B)%9973,但由于A很大,我们只给出n(n=A%9973)( ...
- HDU 5407 CRB and Candies(LCM +最大素因子求逆元)
[题目链接]pid=5407">click here~~ [题目大意]求LCM(Cn0,Cn1,Cn2....Cnn)%MOD 的值 [思路]来图更直观: 这个究竟是怎样推出的.说实话 ...
- hdu_1576A/B(扩展欧几里得求逆元)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1576 A/B Time Limit: 1000/1000 MS (Java/Others) Me ...
- HDU 1576 A/B 数论水题
http://acm.hdu.edu.cn/showproblem.php?pid=1576 写了个ex_gcd的模板...太蠢导致推了很久的公式 这里推导一下: 因为 1 = BX + 9973Y ...
- HDU 1576 A/B (两种解法)
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1576 分析:等式枚举法,由题意可得:, ,代入 , 得:,把变量 合在一起得: :即满足 为 倍 ...
随机推荐
- poj3984《迷宫问题》暑假集训-搜索进阶
K - 迷宫问题 Crawling in process... Crawling failed Time Limit:1000MS Memory Limit:65536KB 64bit ...
- 51nod 1513 && CF570D
题意:给定一棵树,每个节点有一个字母.给定若干个询问,询问某个子树内某一深度的节点是否能将这些节点组合成一个回文串.(深度是以根节点为基准的,不是当前子树根.)数据规模10^5. 神犇题解 子树问题, ...
- zookeeper 配置文件注释
tickTime=2000 initLimit=5 syncLimit=2 dataDir=/opt/shencl/zookeeper/data/data0 dataLogDir=/opt/shenc ...
- Winform中的dataGridView添加自动编号
1.Winform中的dataGridView添加自动编号:http://blog.csdn.net/ohyoyo2014/article/details/38346887 2.如何为datagrid ...
- Python中如何开发一个注册接口小实例
import flask from flask import request #想获取到请求参数的话,就得用这个 server = flask.Flask(__name__) #吧这个python文件 ...
- QListWidget拖放
setDragEnabled() 允许拖 setAcceptDrops()允许放 setDragDropMode(QAbstractItemView.DragDrop)设置拖拽模式 setSelect ...
- web网页打印的方法
WebBrowser.ExecWB的完整说明 个人感觉的:致命缺点-----------------仅仅支持ie浏览器 document.all.WebBrowser.ExecWB WebBrowse ...
- numpy.ndarray类型的数组元素输出时,保留小数点后4位
因为计算结果数组中每个值都是很长的一串小数,看起来比较乱,想格式化一下输出方式. 这是个看起来很简单的问题,但是方法找了很久. 方法也是看起来很简单,用 numpy.set_printoptions( ...
- [原]NYOJ-数的位数-69
大学生程序代写 /* NYOJ69 阶乘数位长度 http://acm.nyist.net/JudgeOnline/problem.php?pid=69 数的长度 时间限制:3000 ms | ...
- loj516dp一般看规律
STL 这...我只能说是...考得是... STL的正确用法? #include<iostream> #include<cstdio> #include<cstdlib ...