大数据代码
#include<iostream>
#include<fstream>
#include<vector>
using namespace std;
struct node{
unsigned long long p;
unsigned long long q;
node(unsigned long long a,unsigned long long b){
p = a;
q = b;
}
};
unsigned long long getIndex(unsigned long long p,unsigned long long q)
{
vector<unsigned long long> vec;
while( p!= 1 || q != 1)
{
if(p > q){ //r
vec.push_back(1);
p -= q;
}else{
vec.push_back(0);
q -= p;
}
}
unsigned long long ret = 1;
for(int i = vec.size()-1;i>=0;i--)
{
ret *= 2;
ret += vec[i];
}
return ret;
}
node getPQ(unsigned long long index)
{
if(index == 1){
return node(1,1);
}
node tmp = getPQ(index/2);
if(index%2 == 0){
tmp.q += tmp.p;
}else{
tmp.p += tmp.q;
}
return tmp;
}
int main()
{
ifstream in("B-large-practice.in");
ofstream out("bs.out");
int command;
unsigned long long n,p,q,index;
in >> n;
for(unsigned long long i = 0;i< n;i++)
{
in>> command;
out<<"Case #"<<i+1<<": ";
if(command == 1){
in>>index;
node tmp = getPQ(index);
out<<tmp.p<<" "<<tmp.q<<endl;
}else if(command == 2){
in>>p>>q;
out<<getIndex(p,q)<<endl;
}
}
return 0;
}