Luogu P2613 【模板】有理数取余

时间:2023-03-10 02:38:27
Luogu P2613 【模板】有理数取余

题目链接 \(Click\) \(Here\)

真心没啥东西,只要能\(Get\)到在数字输入的时候按位取模,以及除数也可以直接取模就可以了。(把每个数看做乘法原理和加法原理构造起来的即可。)

#include <bits/stdc++.h>
using namespace std; const int Mod = 19260817; int read_Mod () {
int s = 0, ch = getchar ();
while ('9' < ch || ch < '0') {
ch = getchar ();
}
while ('0' <= ch && ch <= '9') {
s = (s * 10 + ch - '0') % Mod;
ch = getchar ();
}
return s;
} int fpow (int x, int y) {
int res = 1;
while (y) {
if (y & 1) {
res = 1LL * res * x % Mod;
}
x = 1LL * x * x % Mod;
y >>= 1;
}
return res;
} int main () {
int a = read_Mod (), b = read_Mod ();
if (b == 0) cout << "Angry!" << endl;
else cout << (1LL * a * fpow (b, Mod - 2)) % Mod << endl;
}