题目链接

Problem Description
要求(A/B)%9973,但由于A很大,我们只给出n(n=A%9973)(我们给定的A必能被B整除,且gcd(B,9973) = 1)。
 
Input
数据的第一行是一个T,表示有T组数据。
每组数据有两个数n(0 <= n < 9973)和B(1 <= B <= 10^9)。
 
Output
对应每组数据输出(A/B)%9973。
 
Sample Input
2
1000 53
87 123456789
 
Sample Output
7922
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 (求逆元)的更多相关文章

  1. HDU 1576 A/B( 逆元水 )

    链接:传送门 思路: 现在给出 n = A % 9973,n = A - A/9973×9973,已知 B|A ,设 A = Bx,可以得到如下形式的式子:Bx + 9973×y = n ,因为gcd ...

  2. hdu 1576 求逆元

    题意:给出n=A mod 9973和B,求(A/B) mod 9973 昨天用扩展欧几里得做过这题,其实用逆元也可以做. 逆元的定义:例如a*b≡1 (mod m),则b就是a关于m的逆元. 求逆元方 ...

  3. 【hdu 1576】A/B(数论--拓展欧几里德 求逆元 模版题)

    题意:给出 A%9973 和 B,求(A/B)%9973的值. 解法:拓展欧几里德求逆元.由于同余的性质只有在 * 和 + 的情况下一直成立,我们要把 /B 转化为 *B-1,也就是求逆元. 对于 B ...

  4. HDU 5768Lucky7(多校第四场)容斥+中国剩余定理(扩展欧几里德求逆元的)+快速乘法

    地址:http://acm.hdu.edu.cn/showproblem.php?pid=5768 Lucky7 Time Limit: 2000/1000 MS (Java/Others)    M ...

  5. hdu 1576 A/B 【扩展欧几里得】【逆元】

    <题目链接> <转载于 >>> > A/B Problem Description 要求(A/B)%9973,但由于A很大,我们只给出n(n=A%9973)( ...

  6. HDU 5407 CRB and Candies(LCM +最大素因子求逆元)

    [题目链接]pid=5407">click here~~ [题目大意]求LCM(Cn0,Cn1,Cn2....Cnn)%MOD 的值 [思路]来图更直观: 这个究竟是怎样推出的.说实话 ...

  7. hdu_1576A/B(扩展欧几里得求逆元)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1576 A/B Time Limit: 1000/1000 MS (Java/Others)    Me ...

  8. HDU 1576 A/B 数论水题

    http://acm.hdu.edu.cn/showproblem.php?pid=1576 写了个ex_gcd的模板...太蠢导致推了很久的公式 这里推导一下: 因为 1 = BX + 9973Y ...

  9. HDU 1576 A/B (两种解法)

    原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1576 分析:等式枚举法,由题意可得:, ,代入 ,    得:,把变量 合在一起得: :即满足 为 倍 ...

随机推荐

  1. Spring Cloud之搭建动态Zuul网关路由转发

    传统方式将路由规则配置在配置文件中,如果路由规则发生了改变,需要重启服务器.这时候我们结合上节课内容整合SpringCloud Config分布式配置中心,实现动态路由规则. 将yml的内容粘贴到码云 ...

  2. LINQ 学习路程 -- 查询例子

    IList<Student> studentList = new List<Student>() { , StudentName = , StandardID = } , , ...

  3. Docker学习(二)

    docker run ubuntu /bin/echo 'Hello world' docker run -t -i ubuntu /bin/bash docker run  命令运行一个容器 -t ...

  4. MySQL中处理Null时要注意两大陷阱

    MySQL数据库是一个基于结构化数据的开源数据库.SQL语句是MySQL数据库中核心语言.不过在MySQL数据库中执行SQL语句,需要小心两个陷阱. 陷阱一:空值不一定为空 空值是一个比较特殊的字段. ...

  5. django使用html模板减少代码

    看下面两个页面: —————————————————————————————————————————————————————————————————————————————————— 一个显示文章列表 ...

  6. How to handle Imbalanced Classification Problems in machine learning?

    How to handle Imbalanced Classification Problems in machine learning? from:https://www.analyticsvidh ...

  7. SpringBoot_04_热部署

    二.参考资料 1.Spring Boot 系列(六)web开发-Spring Boot 热部署

  8. Handler的另外一种用法(HandlerThread)

    直接上代码: public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Handler ...

  9. yahoo的30条优化规则

    1.尽量减少HTTP请求次数 终端用户响应的时间中,有80%用于下载各项内容.这部分时间包括下载页面中的图像.样式表.脚本.Flash等.通过减少页面中的元素可以减少HTTP请求的次数.这是提高网页速 ...

  10. UVA12163 游戏

    题目大意 现在有两个人在一个n个结点的有向图上玩一个双人游戏,保证图中无环和自圈.游戏的规则如下:1.初始的时候$i$号点有一个正权值$value_i$2.两名玩家依次操作,每个玩家在当前回合可以选择 ...