簡單的數論題
發現並無對小數取餘這一說,因此咱們把原式化一下,\(c=\frac{a}{b}\equiv a\times b^{-1}(mod\ p)\),由於\(p\)是質數,因此咱們根據費馬小定理,有\(a\times b^{p-2}\equiv c(mod\ p)\),因而咱們求\(a\times b^{p-2}(mod\ p)\)就行了,注意\(b=0\)時無解。
輸入的話根據同餘的同加性和同乘性,在讀入優化里加一個取餘就行了git
#include <bits/stdc++.h> #define int long long using namespace std; const int mod = 19260817; int a, b; inline int read() { int x = 0, f = 0; char ch = getchar(); while (!isdigit(ch)) f |= (ch == '-'), ch = getchar(); while (isdigit(ch)) x = (x * 10 + ch - '0') % mod, ch = getchar(); return f ? -x : x; } int qpow(int a, int b) { int ans = 1; while (b) { if (b & 1) ans = (ans * a) % mod; a = (a * a) % mod, b >>= 1; } return ans; } main() { a = read(), b = read(); if (b == 0) { printf("Angry!"); return 0; } cout << (qpow(b, mod - 2) * a % mod + mod) % mod; }