zoukankan      html  css  js  c++  java
  • 求逆元 HDU 2516

    A/B

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


    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
     
    Recommend
    linle
    #include <stdio.h>
    #include <iostream>
    #define LL long long
    using namespace std;
    #define M 9973
    void gcd(LL a,LL b,LL &d,LL &x,LL &y)
    {
         if(!b){d=a;x=1;y=0;}
         else{gcd(b,a%b,d,y,x);y-=x*(a/b);}
    }
    LL inv(LL a,LL n)
    {
         LL d,x,y;
         gcd(a,n,d,x,y);
         return d==1?(x+n)%n:-1;
    }
    int main()
    {
         int t;
         LL a,b;
         scanf("%d",&t);
         while(t--)
         {
            scanf("%lld%lld",&a,&b);
            LL s=inv(b,M);
            printf("%lld
    ",s*a%M);
         }
         return 0;
    }
  • 相关阅读:
    国内外手机号码正则表达式
    apt安装Neo4j
    经典决策树模型
    自动文档摘要评价方法
    scrapy-splash解析javascript
    ubuntu安装splash
    iptables的删除命令中的相关问题
    ARTS第七周
    ARTS第六周
    ARTS第五周
  • 原文地址:https://www.cnblogs.com/yuanbo123/p/6776081.html
Copyright © 2011-2022 走看看