题目链接: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的更多相关文章

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

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

  2. hdu 5512 Pagodas 扩展欧几里得推导+GCD

    题目链接 题意:开始有a,b两点,之后可以按照a-b,a+b的方法生成[1,n]中没有的点,Yuwgna 为先手, Iaka后手.最后不能再生成点的一方输: (1 <= n <= 2000 ...

  3. hdu 1573 A/B (扩展欧几里得)

    Problem Description 要求(A/B)%9973,但由于A很大,我们只给出n(n=A%9973)(我们给定的A必能被B整除,且gcd(B,9973)= 1). Input 数据的第一行 ...

  4. HDU 5114 扩展欧几里得

    题目大意:给你两个球的坐标 他们都往(1, 1)这个方向以相同的速度走,问你他们在哪个位置碰撞. 思路:这种题目需要把x方向和y方向分开来算周期,两个不同周期需要用扩展欧几里得来求第一次相遇. #in ...

  5. [ACM] hdu 3923 Invoker (Poyla计数,高速幂运算,扩展欧几里得或费马小定理)

    Invoker Problem Description On of Vance's favourite hero is Invoker, Kael. As many people knows Kael ...

  6. poj 2891 扩展欧几里得迭代解同余方程组

    Reference: http://www.cnblogs.com/ka200812/archive/2011/09/02/2164404.html 之前说过中国剩余定理传统解法的条件是m[i]两两互 ...

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

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

  8. 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个点,求射 ...

  9. 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 ...

随机推荐

  1. ASPxCallback组件(珍藏版)

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs ...

  2. Appium -选择、操作元素4

    webvie的测试 混合(Hybrid)应用 一部分是原生界面和代码,而一部分是内嵌网页 比如微信.支付宝 内嵌了一个浏览器内核,由浏览器内核实现的 安卓应用中的内嵌的展示网页内容的模块,我们称之为w ...

  3. 比较sql server两个数据库

    比较sql server两个数据库 http://opendbdiff.codeplex.com/ http://www.red-gate.com/ 有SQL Compare和SQL Prompt 开 ...

  4. itnba试做

    http://www.itnba.com/ 首先标题.ico添加 <link href="title.ico" rel="shortcut icon" / ...

  5. day03-变量

    Python中的变量类型有: int:带正负号的整数long:在python2中表示长整数,在python3中被放弃complex:复数str:字符串True,False:布尔list:列表dict: ...

  6. jinjia

    https://www.cnblogs.com/dachenzi/p/8242713.html

  7. AJax知识介绍

    参考:http://www.runoob.com/ajax/ajax-asp-php.html

  8. ubuntu安装pgAdmin 4

    One way to install pgadmin4 is to download its Python wheel at https://www.postgresql.org/ftp/pgadmi ...

  9. while read line

    # grep "请求报文:" application-20170822-*.log >> applog # cat applog|cut -d ":" ...

  10. docker的完整解决方案2

    这个解决方案很简单 使用docker自带的swarm 首先初始化集群 docker swarm init 然后其余节点加入集群,这个就不说,太简单了 集群初始化后,可以查看下集群状态 docker n ...