一个很有意思的写法

#include
#include
#include
#include
typedef long long ll;
using namespace std;
ll s[1000100];
int main(){
int a,n;
while(scanf("%d %d",&a,&n)){
priority_queue,greater > q;
int pos=0;
q.push(a);
int pret=0;
while(!q.empty()){
ll t=q.top();q.pop();
if(pret==t)continue;
pret=t;
s[pos++]=t;
if(pos>n+100)break;
q.push(2*t+1);
q.push(3*t+1);
}
printf("%lld\n",s[n-1]);
}
}

你可能感兴趣的:(WHATEVER)