• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
村雨sup
自己选的路,跪着也要走完 XD
博客园    首页    新随笔    联系   管理    订阅  订阅
数论练习(6)——hdu A/B(逆元gcd)

A/B

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


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<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
typedef long long  ll;

const int inf = 0x3f3f3f3f;
const int moder = 1e9 + 7;
const int MAXN=1000010;

ll extgcd(ll a,ll b,ll &x,ll &y)
{
    ll d = a;
    if(b == 0)
    {
        x = 1;
        y = 0;
    }
    else
    {
        d = extgcd(b,a%b,y,x);
        y -= (a/b)*x;
    }
    return d;
}

int main()
{
    int t;
    cin >> t;
    while(t--)
    {
        ll n,a,b,x,y;
        b = 9973;
        cin >> n >> a;
        extgcd(a,b,x,y);
        b = (x%b+b)%b;
        cout << n*b%9973 << endl;
    }

    return 0;
}

 

ax _= 1(mod b)  

x为a膜b的逆元

 
posted on 2018-02-03 22:53  村雨sup  阅读(135)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3