A/B

          Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
          Total Submission(s): 6412    Accepted Submission(s): 5069

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

Author

xhd

Source

 

思路:

(a/b)mod p=?
定义 c为b在mod p意义下的逆元
=a*c mod p = (a mod p * c mod p)mod p

这样我们就有把这道题转换成裸地扩展欧几里得了。。。

代码:

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int n,m,t,a,b,x,y,gcd,ans;
int read()
{
    ,f=; char ch=getchar();
    ; ch=getchar();}
    +ch-'; ch=getchar();}
    return x*f;
}
int exgcd(int a,int b,int &x,int &y)
{
    )
    {
        x=,y=;
        return a;
    }
    int r=exgcd(b,a%b,x,y),tmp;
    tmp=x,x=y,y=tmp-a/b*y;
    return r;
}
int main()
{
    t=read();
    while(t--)
    {
        n=read(),m=read();
        a=m;b=;
        gcd=exgcd(a,b,x,y);
        ) x+=b/gcd;
        ans=(n%b*x%b)%b;
        printf("%d\n",ans);
    }
    ;
}

HDU——1576 A/B的更多相关文章

  1. hdu 1576 A/B

    原题链接:hdu 1576 A/B 同样是用扩展的欧几里得算法.A = 9973k+n = xB,从而转化为:xB-9973k=n求解x即可. 具体扩展欧几里得算法请参考:hdu 2669 Roman ...

  2. HDU 1576 (乘法逆元)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1576 题目大意:求(A/B)mod 9973.但是给出的A是mod形式n,n=A%9973. 解题思 ...

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

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

  4. 【HDU 1576】 A/B

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

  5. 扩展欧几里得 hdu 1576

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1576 不知道扩展欧几里得的同学可以参考:https://blog.csdn.net/zhjchengf ...

  6. HDU 1576 A/B(欧几里德算法延伸)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1576 题目: Problem Description 要求(A/B)%9973,但由于A很大,我们只 ...

  7. HDU 1576 A/B(扩展欧几里德变形)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1576 Problem Description 要求(A/B)%9973,但因为A非常大,我们仅仅给出n ...

  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 分析:等式枚举法,由题意可得:, ,代入 ,    得:,把变量 合在一起得: :即满足 为 倍 ...

  10. hdu 1576 A/B(拓展欧几里得)

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

随机推荐

  1. JavaScript--userAgent

    userAgent 返回用户代理头的字符串表示(就是包括浏览器版本信息等的字符串) 语法 navigator.userAgent 几种浏览的user_agent.,像360的兼容模式用的是IE.极速模 ...

  2. 2017青岛网络赛1008 Chinese Zodiac

    Chinese Zodiac Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) T ...

  3. linux 常用shell命令之wc

    wc:查看文件统计信息 用法:$ wc filename 1. $ wc fileName $ wc fileName X Y Z /Desktop/hello X:表示行数 Y:表示单词数 Z:表示 ...

  4. IIS配置负载均衡

    一.下载Nginx安装包 二.修改nginx.conf文件信息 如图: 三.重新加载Nginx (nginx -s reload) 启动Nginx: start nginx 停止Nginx:nginx ...

  5. ubuntu下编译VLC源码

    http://blog.csdn.net/beitiandijun/article/details/9225591ubuntu下编译VLC源码 分类: 视频处理 2013-07-02 17:33 57 ...

  6. NX自动出图

    小秀一下战果: 1. 自动添加图框2. 自动添加投影视图3. 自动标注外形尺寸4. 根据工艺要求,自动添加公差5. 自动孔表6. 批量打印 欢迎大家积极吐槽哈 [视频演示] http://v.youk ...

  7. 带有空格或tab的字符串的判断

    class test { public static void main(String[] args) { String a = " "; //带有空格的字符串 if ( a.is ...

  8. Codeforces_768_D_(概率dp)

    D. Jon and Orbs time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  9. Java学习2_一些基础2_字符串_16.5.5

    接上一次的博客. 不可变字符串: Java中String类没有提供用于修改字符串的方法.如果想将greeting中的“Hello”改为“Help!”需要先提取所需要的的字符,然后再拼接.即 greet ...

  10. .net core Elasticsearch 查询更新

    记录一下: 数据结构如下: public class ESUserTransaction { public long AccountId { get; set; } public string Var ...