题目

A/9973=n

那么:n= A - A / 9973 * 9973   ……①

设:A/B=x  则A=B*x,代入①  得  n=B*x-A/9973*9973

然后这个方程中的A/9973不要去纠结它,A就当不知道,然后,方程可变成二元方程 B * x - 9973 * y = n ;

故:(x/n)B+(-y/n)9973=1=GCD(B,9973),该方程有解。

  要求x和y,先求X=x/n和Y=-y/n,即先解方程BX+9973Y=1。

  最后,x=X*n。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
const int m = 9973;
void gcd(int a,int b,int &x,int &y)
{
if(b==0)
{
x=1;y=0;
return ;
}
gcd(b,a%b,x,y);
int t = x;
x = y;
y = t - (a/b)*y;
}
int main()
{
int n,a,b,x,y;
scanf("%d",&n);
while(n--)
{
scanf("%d%d",&a,&b);//a=A%9973
gcd(b,m,x,y);
x=(x%m+m)%m;
x = x*a%m;
printf("%d\n",x); }
return 0;
}

其实就是数学当中的类似化简方程之类的题。化简成exgcd可以解决的形式。

hdu 1576 A/B 【扩展欧几里德】的更多相关文章

  1. HDU 1576 A/B 扩展欧几里德算法

    A/B Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submis ...

  2. HDU 2669 Romantic(扩展欧几里德)

    题目链接:pid=2669">http://acm.hdu.edu.cn/showproblem.php?pid=2669 Problem Description The Sky is ...

  3. HDU 2669 Romantic【扩展欧几里德】

    裸的扩展欧几里德,求最小的X,X=((X0%b)+b)%b,每个X都对应一个Y,代入原式求解可得 #include<stdio.h> #include<string.h> ty ...

  4. hdu 1576 A/B (扩展欧几里德简单运用)

    http://acm.hdu.edu.cn/showproblem.php?pid=1576 A/B Time Limit: 1000/1000 MS (Java/Others) Memory Lim ...

  5. HDU 1576 A/B【扩展欧几里德】

    设A/B=x,则A=Bx n=A%9973=A-9973*y=Bx-9973*y 用扩展欧几里德求解 #include<stdio.h> #include<string.h> ...

  6. HDU 2669 Romantic 扩展欧几里德---->解不定方程

    Romantic Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  7. HDU 2669 Romantic(扩展欧几里德, 数学题)

    题目 //第一眼看题目觉得好熟悉,但是还是没想起来//洪湖来写不出来去看了解题报告,发现是裸的 扩展欧几里得 - - /* //扩展欧几里得算法(求 ax+by=gcd )//返回d=gcd(a,b) ...

  8. HDU 3923 Invoker(polya定理+乘法逆元(扩展欧几里德+费马小定理))

    Invoker Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 122768/62768K (Java/Other) Total Subm ...

  9. hdu2669与hdu1576(扩展欧几里德)

    模板: int Extend_Euclid(int a, int b, int &x, int &y){         if(b == 0){             x = 1; ...

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

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

随机推荐

  1. oracle 单表导出导入

    exp username/password@服务名 file=d:\daochu.dmp tables=(tableneme,...)

  2. andorid 计算器

    avtivity_main.xml <?xml version="1.0" encoding="utf-8"?> <GridLayout xm ...

  3. JVM 堆参数调优 (四)

    堆参数调优 1.堆的结构 JAVA7 堆逻辑上分为:新生区.养老区.永久区:实际上堆只有新生区.养老区: Minor GC:轻量的垃圾回收:   Major GC(Full GC):重量级垃圾回收. ...

  4. guide dpdk

    Welcome to DPDK Guide! Contents: Setting up DPDK Important Prerequisites Setting up repositories Red ...

  5. Internet

    0x01 URL的解析/反解析/连接 解析 urlparse()--分解URL # -*- coding: UTF-8 -*- from urlparse import urlparse url = ...

  6. IPV6修复工具

    https://www.cnblogs.com/ysugyl/p/9000940.html

  7. 如何使用Log4j

    如何使用Log4j? 1. Log4j是什么?   Log4j可以帮助调试(有时候debug是发挥不了作 用的)和分析,要下载和了解更详细的内容,还是访问其官方网站吧: http://jakarta. ...

  8. Python之内置函数一

    一:绝对值,abs i = abs(-123) print(i) # 打印结果 123 二:判断真假,all,与any 对于all # 每个元素都为真,才是True # 假,0,None," ...

  9. spring boot中注入jpa时报could not autowire.No beans of 'PersonRepository' type found

    解决方法,在repository加一个注解.如下图所示: @Component

  10. ajax from 提交

    $.ajax({                 cache: true,                 type: "POST",                 url:aj ...