首页 > 其他 > 详细

[洛谷P2613]【模板】有理数取余

时间:2018-09-23 14:45:43      阅读:185      评论:0      收藏:0      [点我收藏+]

题目大意:给你$a,b(a,b\leqslant10^{10001})$,求出$\dfrac a b\equiv1\pmod{19260817}$,无解输出 Angry! 

题解:在读入的时候取模,若$b=0$输出无解,否则正常的求逆就行了

卡点:

 

C++ Code:

#include <cstdio>
#include <cctype>
const long long mod = 19260817;
long long a, b;
inline long long read() {
	long long x;
	char t = getchar();
	while (isspace(t)) t = getchar();
	for (x = t & 15, t = getchar(); isdigit(t); t = getchar()) x = (x * 10 + (t & 15)) % mod;
	return x;
}
void exgcd(long long a, long long b, long long &x, long long &y) {
	if (!b) x = 1, y = 0;
	else exgcd(b, a % b, y, x), y -= a / b * x;
}
inline long long INV(long long a) {
	long long x, y;
	exgcd(a, mod, x, y);
	if (x < 0) x += mod;
	return x;
}
int main() {
	a = read(), b = read();
	if (!b) {
		puts("Angry!");
		return 0;
	}
	printf("%lld\n", a * INV(b) % mod);
	return 0;
}

  

[洛谷P2613]【模板】有理数取余

原文:https://www.cnblogs.com/Memory-of-winter/p/9692412.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!