问题
https://vjudge.net/problem/UVA-10479
分析
找规律:参考:https://www.cnblogs.com/TheRoadToTheGold/p/7429744.html
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long LL;
const int maxn=100000+5;
LL n,lensum[64],len[64];
LL dfs(LL d,LL pos){
if(pos==len[d]) return d;
int num=d-2,cnt=1;
while(num>=0 && pos>len[num]*cnt){
pos-=len[num]*cnt;
--num;
++cnt;
}
pos=(pos-1)%len[num]+1;
return dfs(num,pos);
}
int main(void){
for(int i=0;i<64;++i){
lensum[i]=1LL<<i;
if(i>0) len[i]=1LL<<(i-1);
}
len[0]=1;
lensum[63]=9223372036854775807ll;
while(scanf("%lld",&n)==1 && n){
int p=0;
for(;n>len[p];++p) n-=len[p];
printf("%lld\n",dfs(p,n));
}
return 0;
}