求逆元 HDU 2516
A/B
Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 639    Accepted Submission(s): 517
每组数据有两个数n(0 <= n < 9973)和B(1 <= B <= 10^9)。
#include <stdio.h>
#include <iostream>
#define LL long long
using namespace std;
#define M 9973
void gcd(LL a,LL b,LL &d,LL &x,LL &y)
{
if(!b){d=a;x=;y=;}
else{gcd(b,a%b,d,y,x);y-=x*(a/b);}
}
LL inv(LL a,LL n)
{
LL d,x,y;
gcd(a,n,d,x,y);
return d==?(x+n)%n:-;
}
int main()
{
int t;
LL a,b;
scanf("%d",&t);
while(t--)
{
scanf("%lld%lld",&a,&b);
LL s=inv(b,M);
printf("%lld\n",s*a%M);
}
return ;
}
求逆元 HDU 2516的更多相关文章
- HDU 5768Lucky7(多校第四场)容斥+中国剩余定理(扩展欧几里德求逆元的)+快速乘法
		
地址:http://acm.hdu.edu.cn/showproblem.php?pid=5768 Lucky7 Time Limit: 2000/1000 MS (Java/Others) M ...
 - hdu 1576     求逆元
		
题意:给出n=A mod 9973和B,求(A/B) mod 9973 昨天用扩展欧几里得做过这题,其实用逆元也可以做. 逆元的定义:例如a*b≡1 (mod m),则b就是a关于m的逆元. 求逆元方 ...
 - HDU 5407 CRB and Candies(LCM +最大素因子求逆元)
		
[题目链接]pid=5407">click here~~ [题目大意]求LCM(Cn0,Cn1,Cn2....Cnn)%MOD 的值 [思路]来图更直观: 这个究竟是怎样推出的.说实话 ...
 - 【hdu 1576】A/B(数论--拓展欧几里德 求逆元 模版题)
		
题意:给出 A%9973 和 B,求(A/B)%9973的值. 解法:拓展欧几里德求逆元.由于同余的性质只有在 * 和 + 的情况下一直成立,我们要把 /B 转化为 *B-1,也就是求逆元. 对于 B ...
 - hdu_1576A/B(扩展欧几里得求逆元)
		
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1576 A/B Time Limit: 1000/1000 MS (Java/Others) Me ...
 - CF451E Devu and Flowers (隔板法 容斥原理 Lucas定理 求逆元)
		
Codeforces Round #258 (Div. 2) Devu and Flowers E. Devu and Flowers time limit per test 4 seconds me ...
 - 【板子】gcd、exgcd、乘法逆元、快速幂、快速乘、筛素数、快速求逆元、组合数
		
1.gcd int gcd(int a,int b){ return b?gcd(b,a%b):a; } 2.扩展gcd )extend great common divisor ll exgcd(l ...
 - 【BZOJ-4522】密钥破解       数论 + 模拟  ( Pollard_Rho分解 + Exgcd求逆元 + 快速幂 + 快速乘)
		
4522: [Cqoi2016]密钥破解 Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 290 Solved: 148[Submit][Status ...
 - HDU4869:Turn the pokers(快速幂求逆元+组合数)
		
题意: 给出n次翻转和m张牌,牌相同且一开始背面向上,输入n个数xi,表示xi张牌翻转,问最后得到的牌的情况的总数. 思路: 首先我们可以假设一开始牌背面状态为0,正面则为1,最后即是求ΣC(m,k) ...
 - ZOJ 3609 求逆元
		
Modular Inverse Time Limit: 2 Seconds Memory Limit: 65536 KB The modular modular multiplicative ...
 
随机推荐
- @RequestParam 注解
			
@RequestParam 注解org.springframework.web.bind.annotation.RequestParam注解类型用于将指定的请求参数赋给方法中的形参.使用@Reques ...
 - [Algorithms] Counting Sort
			
Counting sort is a linear time sorting algorithm. It is used when all the numbers fall in a fixed ra ...
 - ASP.Net请求处理机制初步探索之旅 - Part 2 核心(转)
			
开篇:上一篇我们了解了一个请求从客户端发出到服务端接收并转到ASP.Net处理入口的过程,这篇我们开始探索ASP.Net的核心处理部分,借助强大的反编译工具,我们会看到几个熟悉又陌生的名词(类):Ht ...
 - instanceof和isInstance(Object obj) 和isAssignableFrom(Class cls)的区别和联系
			
instanceof和isInstance(Object obj) 和isAssignableFrom(Class cls)的区别和联系 编程的时候可能会遇到一个不知道它属于哪个类的 ...
 - fun_action
			
make an absolute URI from a relative one http://php.net/manual/en/function.header.php <?php /* Re ...
 - python split(),os.path.split()和os.path.splitext()函数用法
			
https://blog.csdn.net/T1243_3/article/details/80170006 # -*- coding:utf-8 -*- """ @ ...
 - python学习笔记(二)— 数据类型
			
一.变量.数据类型 1.计算机顾名思义就是可以做数学计算的机器,因此,计算机程序理所当然地可以处理各种数值.但是,计算机能处理的远不止数值,还可以处理文本.图形.音频.视频.网页等各种各样的数据,不同 ...
 - plotly简单绘制柱状图
			
代码: import plotly.offline as pltoff import plotly.graph_objs as go def bar_charts(name="bar_cha ...
 - python中decorator的用法及原理(一)
			
0. 概念 什么叫装饰器,其实也可以叫做包装器.即对于一个既有的函数func(args),在调用它之前和之后,我们希望都做一些事情,把这个函数包装起来. Python中的装饰器分为两类:函数装饰器和类 ...
 - 吴超老师课程--Hive的执行语句
			
为什么选择Hive? (1)基于Hadoop的大数据的计算/扩展能力(2)支持SQL like查询语言(3)统一的元数据管理(4)简单编程 一:Hive的数据类型(1)基本数据类型tinyint/sm ...