思路讲解

由于p给你的一般是素数,一般不用担心b,p互素的问题,除非b%p=0
AC代码
https://www.luogu.com.cn/record/192866597
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
| #include <iostream> #include <cstring> #include <algorithm> #include <deque> #include <queue> #include <vector> #include <set> #include <map> #include <cmath> #include <bitset> #include <iterator> #include <random> #include <iomanip> #include <cctype>
using namespace std; typedef long long ll; const ll N=static_cast<ll>(2e5)+10; const int m=19260817;
void exgcd(ll a,ll b,ll &x,ll &y){ if(!b) x=1,y=0; else exgcd(b,a%b,y,x),y-=a/b*x; }
inline ll getll(){ char c=getchar(); ll res=0; while (!isdigit(c) && c!=EOF) { c=getchar(); } while (isdigit(c)) { res=((res<<3)+(res<<1)+c-'0')%m; c=getchar(); } return res; }
int main() { ios::sync_with_stdio(false); cin.tie(0);cout.tie(0);
ll a=getll(); ll b=getll(); if(b==0){ cout<<"Angry!"<<endl; return 0; } ll x,y; exgcd(b, m, x, y); cout<<(x*a%m+m)%m<<endl;
return 0; }
|
心路历程(WA,TLE,MLE……)