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
Author
xhd
Source
HDU 2007-1 Programming Contest
题目类型:乘法逆元
算法分析:直接使用乘法逆元求解即可
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
#include <set> #include <bitset> #include <list> #include <map> #include <stack> #include <queue> #include <deque> #include <string> #include <vector> #include <ios> #include <iostream> #include <fstream> #include <sstream> #include <iomanip> #include <algorithm> #include <utility> #include <complex> #include <numeric> #include <functional> #include <cmath> #include <ctime> #include <climits> #include <cstdarg> #include <cstdio> #include <cstdlib> #include <cstring> #include <cctype> #include <cassert> using namespace std; #define CFF freopen ("aaa.txt", "r", stdin) #define CPPFF ifstream cin ("aaa.txt") #define LL long long const int INF = 0x7FFFFFFF; const int MOD = 1e9 + 7; const double EPS = 1e-6; const double PI = 2 * acos (0.0); const int maxn = 1e6 + 66; LL ex_gcd (LL a, LL b, LL &x, LL &y) { if (b == 0) {x = 1; y = 0; return a;} LL d = ex_gcd (b, a % b, y, x); y = y - a / b * x; return d; } LL Sol (LL a, LL b, LL c) { LL x, y, d; d = ex_gcd (a, b, x, y); if (c % d) return -1; x = x * (c / d) % (b / d); if (x < 0) x += b / d; return x; } int main() { // CPPFF; LL t; cin >> t; while (t--) { LL nn, bb; cin >> nn >> bb; LL tt = Sol (bb, 9973, 1); cout << (nn * tt) % 9973 << endl; } return 0; } |
- « 上一篇:hdu1573
- hdu1671:下一篇 »