求助0分(本地测试与数据一模一样)
  • 板块学术版
  • 楼主Second_Gardenia
  • 当前回复3
  • 已保存回复4
  • 发布时间2023/12/23 12:04
  • 上次更新2023/12/23 14:58:48
查看原帖
求助0分(本地测试与数据一模一样)
510908
Second_Gardenia楼主2023/12/23 12:04

P2613 【模板】有理数取余

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define int __int128

const int mod = 19260817;
int a , b , x , y;

inline int read(){
	int s = 0;
	char c = getchar();
	while(isdigit(c)){
		s = (s << 1) + (s << 3) + (c ^ 48);
		s %= mod;
		c = getchar();
	}
	return s;
}
inline void write(int x){
	if(x > 9)write(x / 10);
	putchar('0' + x % 10);
}
inline int extend_gcd(int a , int b , int &x , int &y){
	if(b == 0){
		x = 1 , y = 0;
		return a;
	}
	int d = extend_gcd(b , a % b , y , x);
	y -= a / b * x;
	return d;
}

signed main(){
	a = read();
	b = read();
	int d = extend_gcd(b , mod , x , y);
	if(a % d){
		cout << "Angry!";
		return 0;
	}
	x = ((x * (a / d)) % (mod / d) + (mod / d)) % (mod / d);
	x %= mod;
	write(x);
	return 0;
} 
/*
233
666

18595654
*/
2023/12/23 12:04
加载中...