zoukankan      html  css  js  c++  java
  • hdu 1576 A/B

    A/B

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


    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
     
     
    #include<iostream>
    #include<string.h>
    #include<math.h>
    #define max 0x3f3f3f3f
    #define ll long long
    #define mod 1000000007
    using namespace std;
    ll x,y;
    ll gcd(ll a,ll b)
    {
        return b==0?a:gcd(b,a%b);
    }
    void exgcd(ll a, ll b, ll &x, ll &y)    //拓展欧几里得算法
    {
        if(!b) 
            x = 1, y = 0;
        else
        {
            exgcd(b, a % b, y, x);
            y -= x * (a / b);
        }
    }
    
    ll niyuan(ll a, ll b)   //求a对b取模的逆元
    {
        ll x, y;
        exgcd(a, b, x, y);
        return (x + b) % b;
    }
    int main()
    {
        ll n,m,t;
        scanf("%lld",&t);
        while(t--)
        {
            scanf("%lld%lld",&n,&m);
            m=niyuan(m,9973);
            printf("%lld
    ",n*m%9973);
        }
    }
     
  • 相关阅读:
    JDBC
    「题解」:串串香
    「题解」:树
    「题解」:最近公共祖先
    「题解」:集合论
    「题解」:位运算
    「题解」:序列
    「总结」浅谈主席树
    $My$ $template$(持续更新)
    「题解」:毛三琛
  • 原文地址:https://www.cnblogs.com/-citywall123/p/10693865.html
Copyright © 2011-2022 走看看