比赛 202110省实验桐柏一中普及组联赛 评测结果 AAAAAAAAAA
题目名称 分数约分 最终得分 100
用户昵称 PYD1 运行时间 0.000 s
代码语言 C++ 内存使用 0.00 MiB
提交时间 2021-10-18 19:00:31
显示代码纯文本
#define MAXN 1000

#include <cstdio>
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include <string.h>

using namespace std;

inline int max(int a,int b) {return a > b ? a : b;}

struct bign{
	int len,a[MAXN + 1];
	bign () {memset(a,0,sizeof(a)),len = 1;}
	bign (int num){
		char s[MAXN + 1];
		sprintf(s,"%d",num);
		*this = s;
	}
	bign (char * num){
		if (num[0] == '0'){
			len = 1,memset(a,0,sizeof(a));
		}else{
			for (int i = 0;num[i] == 48;num++) ;
			len = strlen(num);
			for (int i = 0;i < len;i++) a[i] = (num[len - i - 1] ^ 48);
		}
	}
	bign operator = (int num){
		char s[MAXN + 1];
		sprintf(s,"%d",num);
		*this = s;
		return *this;
	}
	bign operator = (char * num){
	if (num[0] == '0'){
			len = 1,memset(a,0,sizeof(a));
		}else{
			for (int i = 0;num[i] == 48;num++) ;
			len = strlen(num);
			for (int i = 0;i < len;i++) a[i] = (num[len - i - 1] ^ 48);
		}
		return *this;
	}
	bign operator + (const bign & b){
		bign ans;
		ans.len = 0;
		for (int i = 0,j = 0;j || i < max(len,b.len);i++){
			if (i < len) j += a[i];
			if (i < b.len) j += b.a[i];
			ans.a[ans.len++] = j % 10;
			j /= 10;
		}
		return ans;
	}
	bign operator += (bign & b) {return *this = *this + b;}
	void clean(){
		while (len > 1 && !a[len - 1]) --len;
		if (len == 0) len = 1,a[0] = 0;
	}
	bign operator * (bign & b){
		bign ans;
		ans.len = len + b.len;
		for (int i = 0;i < len;i++){
			for (int j = 0;j < b.len;j++) ans.a[i + j] += a[i] * b.a[j];
		}
		for (int i = 0;i < ans.len;i++) ans.a[i + 1] += ans.a[i] / 10,ans.a[i] %= 10;
		ans.clean();
		return ans;
	}
	bign operator *= (bign & b) {return *this = (*this) * b;}
	bign operator - (bign & b){//without negative result or numbers
		bign ans;
		ans.len = 0;
		for (int i = 0,j = 0;i < len;i++){
			int x = a[i] - j;
			if (i < b.len) x -= b.a[i];
			if (x >= 0) j = 0;
			else j = 1,x += 10;
			ans.a[ans.len++] = x;
		}
		ans.clean();
		return ans;
	}
	bign operator -= (bign & b) {return *this = *this - b;}
	bign operator / (bign & b){
		bign ans,f,ten = 10;
		for (int i = len - 1;i >= 0;i--){
			f *= ten;
			f.a[0] = a[i];
			while (f >= b) f -= b,ans.a[i]++;
		}
		ans.len = len,ans.clean();
		return ans;
	}
	bign operator /= (bign & b) {return *this = *this / b;}
	bign operator % (bign & b){
		bign t = *this / b * b;
		t = *this - t;
		t.clean();
		return t;
	}
	bign operator %= (bign & b) {return *this = *this % b;}
	bool operator < (bign & b){
		if (len != b.len) return len < b.len;
		for (int i = len - 1;i >= 0;i--){
			if (a[i] != b.a[i]) return a[i] < b.a[i];
		}
		return 0;
	}
	bool operator > (bign & b){
		if (len != b.len) return len > b.len;
		for (int i = len - 1;i >= 0;i--){
			if (a[i] != b.a[i]) return a[i] > b.a[i];
		}
		return 0;
	}
	bool operator == (bign & b){
		if (len != b.len) return 0;
		for (int i = len - 1;i >= 0;i--){
			if (a[i] != b.a[i]) return 0;
		}
		return 1;
	}
	bool operator != (bign & b) {return !(*this == b);}
	bool operator >= (bign & b) {return *this > b || *this == b;}
	bool operator <= (bign & b) {return *this < b || *this == b;}
};

bign a,b,ten(10),zero(0);

inline void read(bign &t){
	register char c = getchar();
	while (c < 48 || c > 57) c = getchar();
	while (c >= 48 && c <= 57) t = t * ten + bign(c ^ 48),c = getchar();
}

bign gcd(bign x,bign y){
	if (y == zero) return x;
	return gcd(y,x % y);
}

int main(){
	freopen("yuefen.in","r",stdin);
	freopen("yuefen.out","w",stdout);
	zero.len = 1;read(a),read(b);
	bign tmp = gcd(b,a);
	a = a / tmp,b = b / tmp;
	for (int i = a.len - 1;i >= 0;i--) printf("%d",a.a[i]);
	putchar(' ');
	for (int i = b.len - 1;i >= 0;i--) printf("%d",b.a[i]);
	return 0;
}