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);
    }
    ;
}

最新文章

  1. Linux之CentOS 常用命令
  2. 重写ajax方法实现异步请求session过期时跳转登录页面
  3. 《BI那点儿事》三国人物智力分布状态分析
  4. ubuntu开机遇到-您的当前网络有.local域,我们不建议这样做而且这与AVAHI网络服务探测不兼容。该服务已被禁用
  5. C#获取程序所在目录路径
  6. 分享web前端七款HTML5 Loading动画特效集锦
  7. Spring MVC之LocaleResolver(解析用户区域)
  8. POJ 1845
  9. c#图像处理入门
  10. ORACLE备份手记
  11. 使用python写appium用例
  12. 使用ABP打造SAAS系统(1)——环境准备
  13. 模块化编程node
  14. Crash CodeForces - 417B
  15. PHP 环境搭建篇
  16. Base64 image
  17. Automatically migrating data to new machines kafka集群扩充迁移topic
  18. MVC中的分部视图
  19. Spring之AOP由浅入深
  20. turtle库实现汉诺塔

热门文章

  1. js计算每月的天数
  2. 一个Velocity Template Language学习的框架
  3. lua调用java java调用lua[转载]
  4. 编写UI自动化测试用例原则
  5. RabbitMQ一:消息队列的认识
  6. SQL数据库基础知识——抽象类
  7. LN : leetcode 3 Longest Substring Without Repeating Characters
  8. cocos2d-x android 环境部署
  9. redis学习-字典
  10. Spark学习之RDD编程(2)