Click
Here to go back to the homepage.
A Rational Sequence (Take 3) Solution:
#include <bits/stdc++.h>
using namespace std;
int main(){
// #ifndef TESTING
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
unsigned int cases, set, n;
cin >> cases;
while(cin >> set){
cin >> n;
stack<bool> location;
while(n != 1){
if(n & 1){
location.push(false);
} else {
location.push(true);
}
n >>= 1;
}
int n = 1, d = 1;
while(location.size() > 0){
bool instruction = location.top();
location.pop();
if(instruction){
d += n;
} else {
n += d;
}
}
cout << set << " " << n << "/" << d << endl;
}
return 0;
}