扩展欧几里得 hdu 1576
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1576
不知道扩展欧几里得的同学可以参考:https://blog.csdn.net/zhjchengfeng5/article/details/7786595
我的推理:
这图片是真的大啊...
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<vector>
#include<fstream>
#include<set>
#include<cstdio>
using namespace std;
#define eps 1e-8
typedef long long ll;
#define INF 0x3f3f3f3f
ll n,B,d,x,y;
int t;
void ex_gcd(ll a,ll b ,ll &d,ll &x,ll &y)
{
if(!b)
{
d=a;
x=;
y=;
return;
}
ex_gcd(b,a%b,d,y,x);
y-=x*(a/b);
}
int main()
{
cin>>t;
while(t--)
{
cin>>n>>B;
ex_gcd(B,,d,x,y);
x*=n; //这里d一定是1,因为gcd(B,9973)==1
x%=;
if(x<) //在这里如果<变成<=也可以ac,但是我觉得不能加,否则应该会出现x=9973的情况
x+=;
cout<<x<<endl;
}
return ;
}
扩展欧几里得 hdu 1576的更多相关文章
- hdu 1576 A/B 【扩展欧几里得】【逆元】
<题目链接> <转载于 >>> > A/B Problem Description 要求(A/B)%9973,但由于A很大,我们只给出n(n=A%9973)( ...
- hdu 5512 Pagodas 扩展欧几里得推导+GCD
题目链接 题意:开始有a,b两点,之后可以按照a-b,a+b的方法生成[1,n]中没有的点,Yuwgna 为先手, Iaka后手.最后不能再生成点的一方输: (1 <= n <= 2000 ...
- hdu 1573 A/B (扩展欧几里得)
Problem Description 要求(A/B)%9973,但由于A很大,我们只给出n(n=A%9973)(我们给定的A必能被B整除,且gcd(B,9973)= 1). Input 数据的第一行 ...
- HDU 5114 扩展欧几里得
题目大意:给你两个球的坐标 他们都往(1, 1)这个方向以相同的速度走,问你他们在哪个位置碰撞. 思路:这种题目需要把x方向和y方向分开来算周期,两个不同周期需要用扩展欧几里得来求第一次相遇. #in ...
- [ACM] hdu 3923 Invoker (Poyla计数,高速幂运算,扩展欧几里得或费马小定理)
Invoker Problem Description On of Vance's favourite hero is Invoker, Kael. As many people knows Kael ...
- poj 2891 扩展欧几里得迭代解同余方程组
Reference: http://www.cnblogs.com/ka200812/archive/2011/09/02/2164404.html 之前说过中国剩余定理传统解法的条件是m[i]两两互 ...
- hdu_1576A/B(扩展欧几里得求逆元)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1576 A/B Time Limit: 1000/1000 MS (Java/Others) Me ...
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) C.Ray Tracing (模拟或扩展欧几里得)
http://codeforces.com/contest/724/problem/C 题目大意: 在一个n*m的盒子里,从(0,0)射出一条每秒位移为(1,1)的射线,遵从反射定律,给出k个点,求射 ...
- Root(hdu5777+扩展欧几里得+原根)2015 Multi-University Training Contest 7
Root Time Limit: 30000/15000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Su ...
随机推荐
- Human Interface Device (HID) Class Decoder
http://www.usblyzer.com/usb-human-interface-device-hid-class-decoder.htm Human Interface Device (H ...
- 使用STM32的USART的同步模式Synchronous调戏SPI[2] 【实现spi 9bit】
[原创出品§转载请注明出处] 出处:http://www.cnblogs.com/libra13179/p/7064533.html 上回说道使用USART的来模拟SPI通讯.说说一下我什么写这个的原 ...
- Collection List接口
常用的:ArrayList,Vector 特点:有序的,允许多个空值
- Linux服务器mysql,nginx等自动停止的排查,以及解决方法
最近发现自己使用的某台云服务武器只要稍微流量大一点,就会出现莫名的的数据库连接错误的情况 ,然后连上服务器查看,发现mysql进程被结束了,经常出现这种情况,这还怎么得了,然后第一时间查看mysql日 ...
- BBS-基于forms组件和ajax实现注册功能
http://www.cnblogs.com/yuanchenqi/articles/7638956.html 1.设计注册页面 views.py from django import forms c ...
- css-图片垂直居中
1. img { vertical-align: middle; } 2. <body> <div> <img src="1.jpg" alt=& ...
- LeetCode OJ 60. Permutation Sequence
题目 The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of th ...
- npm run dev 报错:missing script:dev
一.问题: 今天在运行vue项目时,在mac终端输入npm run dev,结果报错: 翻译是: npm错误:缺少script:dev npm错误:完整路径见:users/mymac/ .npm/_l ...
- CrazySNS has on line - And you'll see why 1984 won't be like "1984."
On May 10th, CrazySNS has on line , And you will see why 1984 won’t be like "1984."
- Matlab实现单层感知机网络识别字母
感知机网络的参数设置 % 具体用法: % net=newp(pr,T,TF,LF); % % pr: pr是一个R×2的矩阵,R为感知器中输入向量的维度(本例中使用35个字符表征一个字母,那么其维度为 ...