QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#688240#2933. Sequinary Numeralskevinyang#Compile Error//C++141.0kb2024-10-30 01:26:102024-10-30 01:26:11

Judging History

你现在查看的是最新测评结果

  • [2024-10-30 01:26:11]
  • 评测
  • [2024-10-30 01:26:10]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

pii reduce(pii a){
	int x = a.first;
	int y = a.second;
	int g = gcd(x,y);
	x/=g;
	y/=g;
	return {x,y};
}

pii mul(pii a, pii b){
	return reduce(make_pair(a.first * b.first, a.second * b.second));
}

pii add(pii a, pii b){
	int d1 = a.second;
	int d2 = b.second;
	a.first *= d2;
	a.second *= d2;
	b.first *= d1;
	b.second *= d1;
	return reduce({a.first + b.first,a.second});
}

signed main() {
	cin.tie(0)->sync_with_stdio(0);
	string s;
	cin >> s;
	pii base = {3,2};
	pii cur = {0,1};
	for(char c : s){
		pii v = {c - '0',1};
		cur = mul(cur,base);
		cur = add(cur,v);
	}
	if(cur.second == 1){
		cout << cur.first << '\n';
	}
	else{
		cout << cur.first/cur.second << ' ' << cur.first%cur.second << '/' << cur.second << '\n';
	}
	return 0;
}

详细

answer.code: In function ‘pii reduce(pii)’:
answer.code:15:17: error: ‘gcd’ was not declared in this scope
   15 |         int g = gcd(x,y);
      |                 ^~~