zoukankan      html  css  js  c++  java
  • hdu 1576 A/B (求逆元)

    题目链接

    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
     
     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <cstdlib>
     5 #include <cmath>
     6 #include <algorithm>
     7 #define LL __int64
     8 const int maxn = 1e3 + 10;
     9 const int mo = 9973;
    10 using namespace std;
    11 
    12 void exgcd(LL a, LL b, LL &d, LL &x, LL &y)
    13 {
    14     if(!b) {d = a; x = 1; y = 0;}
    15     else{ exgcd(b, a%b, d, y, x); y -= x*(a/b); }
    16 }
    17 
    18 LL mo_reve(LL a, LL n)
    19 {
    20     LL x, y;
    21     LL d;
    22     exgcd(a, n, d, x, y);
    23     if(d==1) return (x%n+n)%n;
    24     else return -1;
    25 }
    26 
    27 int main()
    28 {
    29      int t, n, b;
    30      scanf("%d", &t);
    31      while(t--)
    32      {
    33          scanf("%d%d", &n, &b);
    34          int x = mo_reve(b, mo);
    35          printf("%d
    ", n*x%mo);
    36      }
    37      return 0;
    38 }
  • 相关阅读:
    centos7添加firewalld规则
    centos7安装redis5
    Oracle 监听
    创建Oracle表空间及用户
    nginx+keepalive
    oracle 修改端口
    Oracle新建数据库
    Redhat7.5安装JBOSS4.2.0
    kubernetes的一些基本命令
    安装python3.6后使用pip报错
  • 原文地址:https://www.cnblogs.com/bfshm/p/4106844.html
Copyright © 2011-2022 走看看