QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#710982 | #2933. Sequinary Numerals | BackToSquare1 | WA | 1ms | 3992kb | C++20 | 2.0kb | 2024-11-04 23:35:46 | 2024-11-04 23:35:47 |
Judging History
answer
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
// using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pl;
typedef pair<ld,ld> pd;
typedef vector<ll> vl;
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define G(x) ll x; cin >> x;
#define F(i, l, r) for (ll i = l; i < (r); ++i)
#define all(a) begin(a), end(a)
#define K first
#define V second
#define OK(i,j) i >= 0 && i < n && j >= 0 && j < m
#define NN 2505
#define MM 5005
#define MOD 1000000007
struct frac{
ll num = 0;
ll denom = 1;
frac operator+(frac a) {
frac b;
b.num = num*a.denom + a.num*denom;
b.denom = denom*a.denom;
b.reduce();
return b;
}
frac operator*(frac a) {
frac b;
b.num = num*a.num;
b.denom = denom*a.denom;
b.reduce();
return b;
}
void reduce() {
ll g = gcd(num,denom);
if(g == 0) return;
num /= g;
denom /= g;
}
pair<ll,frac> proper() {
frac a;
ll b;
b = num/denom;
a.num = num%denom;
a.denom = denom;
return {b,a};
}
};
void solve() {
string s;
cin >> s;
ll k = s.length();
frac ans;
ans.num = 0;
ans.denom = 1;
for(ll i=0;i<k;i++) {
ll d = (ll)(s[i] - '0');
frac a;
a.num = d;
a.denom = 1;
frac b;
b.num = (ll)(pow(3,k-i-1));
b.denom = (ll)(pow(2,k-i-1));
ans = ans + a*b;
}
pair<ll,frac> c = ans.proper();
if(c.V.num == 0) cout << c.K << '\n';
else cout << c.K << ' ' << c.V.num << '/' << c.V.denom << '\n';
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cout << fixed << setprecision(10);
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3992kb
input:
2101
output:
10
result:
ok single line: '10'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3824kb
input:
201
output:
5 1/2
result:
ok single line: '5 1/2'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3760kb
input:
2010211122112221202012
output:
16541 873801/1048576
result:
ok single line: '16541 873801/1048576'
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 3856kb
input:
22222222222222222222222222222222
output:
13147 572407425/1073741824
result:
wrong answer 1st lines differ - expected: '1725755 572407425/1073741824', found: '13147 572407425/1073741824'