zoukankan      html  css  js  c++  java
  • hdu1576 mod 运算的逆元

    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 <cstdio>
    #include <iostream>
    
    using namespace std;
    
    int main(){
    	int t;
    	cin >> t;
    	
    	while(t --){
    		long long int n,b;
    		int i;
    		cin >> n >> b;
    		for(i = 1;i <= 9973;i++){
    			if(i * b % 9973 == 1){
    				break;
    			}
    		}
    		cout << n * i % 9973 << endl;
    	}
    	return 0;
    } 

    a/b % n  = a * b^-1 % n,也就是a/b能够换成a乘上b对于模n群的逆元的模

  • 相关阅读:
    第63天python学习异常
    第62天python 学习TCP三次握手四次挥手详解
    文件操作
    内置函数
    函数递归
    函数补充
    函数
    购物车程序作业
    集合内置函数
    字典三级菜单
  • 原文地址:https://www.cnblogs.com/yangykaifa/p/7162005.html
Copyright © 2011-2022 走看看