exCRT求调 为什么最后两个点WA
查看原帖
exCRT求调 为什么最后两个点WA
248302
d0j1a_1701楼主2021/10/5 15:46
#include <algorithm>
#include <iostream>
#include <cassert>
using namespace std;
struct IO {
#ifdef FIO
	const static int BUFSIZE = 1 << 20;
	char buf[BUFSIZE], obuf[BUFSIZE], *p1, *p2, *pp;
#define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,BUFSIZE,stdin),p1==p2)?EOF:*p1++)
	void pc(char c) {
		if(pp - obuf == BUFSIZE)	fwrite(obuf, 1, BUFSIZE, stdout), pp = obuf;
		*pp = c, pp++;
	}
	IO() {
		p1 = buf, p2 = buf, pp = obuf;
	}
	~IO() {
		fwrite(obuf, 1, pp - obuf, stdout);
	}
#else
#define gc getchar
#define pc putchar
#endif
	template<typename Tp = int>
	inline Tp read() {
		Tp s = 0;
		int f = 1;
		char ch = gc();
		while(!isdigit(ch)) f = (ch == '-' ? -1 : 1), ch = gc();
		while(isdigit(ch))  s = s * 10 + (ch ^ 48), ch = gc();
		return s * f;
	}
	template<typename Tp>
	void read(Tp &x) {
		x = read();
	}
	template<typename Tp, typename... Ts>
	void read(Tp &x, Ts &...val) {
		x = read<Tp>();
		read(val...);
	}
	template<typename Tp>
	void write(Tp x) {
		if(x < 0)	pc('-'), x = -x;
		static char sta[20];
		int top = 0;
		do sta[top++] = x % 10 + '0', x /= 10;
		while(x);
		while(top)	pc(sta[--top]);
	}
	template<typename Tp, typename... Ts>
	void write(Tp x, Ts... val) {
		write(x);
		pc(' ');
		write(val...);
	}
	template<typename... Ts>
	void writeln(Ts... val) {
		write(val...);
		pc('\n');
	}
} io;
__int128_t exgcd(__int128_t a, __int128_t b, __int128_t &x, __int128_t &y) {
	if(!b) {
		x = 1, y = 0;
		return a;
	}
	__int128_t t = exgcd(b, a % b, y, x);
	y -= a / b * x;
	return t;
}
__int128_t lcm(__int128_t  a, __int128_t b) {
	return a / __gcd(a, b) * b;
}
__int128_t a1, m1, a2, m2;
int n;
int main() {
	n = io.read();
	io.read(m1, a1);
	for(int i = 2; i <= n; i++) {
		io.read(m2, a2);
		__int128_t p, q, gcd = exgcd(m1, m2, p, q), m = m2 / gcd, c = (a2 - a1 % m2 + m2) % m2;
		p = p * (c / gcd) % m;
		a1 += p * m1;
		m1 *= m;
		a1 = (a1 % m1 + m1) % m1;
	}
	io.writeln((a1 % m1 + m1) % m1);
	system("pause");
	return 0;
}

2021/10/5 15:46
加载中...