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
| #include<iostream> #include<cstdio> #include<cmath> #include<cstring> #include<cstdlib> #include<algorithm> #include<ctime> #include<iomanip> #include<queue> #include<stack> #include<map> #include<vector> #define gh() getchar() #define underMax(x,y) ((x)>(y)?(x):(y)) #define underMin(x,y) ((x)<(y)?(x):(y)) typedef long long LL; using namespace std; const int MAXN=1e5+1; template<class T> inline void underRead(T &x) { x=0; char ch=gh(),t=0; while(ch<'0'||ch>'9') t|=ch=='-',ch=gh(); while(ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+(ch^48),ch=gh(); if(t) x=-x; } int N; struct Node { LL type,mod; }Num[MAXN]; LL M[MAXN],Mul=1,Mi[MAXN],X; inline void underExgcd(LL a,LL b,LL &x,LL &y) { if(!b) { x=1,y=0; return ; } underExgcd(b,a%b,x,y); LL z=x;x=y;y=z-y*(a/b); } int main() { underRead(N); for(int i=1;i<=N;++i) { underRead(Num[i].type),underRead(Num[i].mod); Mul*=Num[i].type; } for(int t=1;t<=N;++t) { Mi[t]=Mul/Num[t].type; LL x=0,y=0; underExgcd(Mi[t],Num[t].type,x,y); X+=Num[t].mod*Mi[t]*(x<0?x+Num[t].type:x); } printf("%lld",X%Mul); return 0; }
|
Gitalk 加载中 ...