ZJNU 1310 - 排队——中高级

追踪1号队员,取他回到原来位置需要的次数

#include<stdio.h>
int main(){
    int T,t,n,ans,x;
    scanf("%d",&T);
    for(t=1;t<=T;t++){
        scanf("%d",&n);
        ans=x=1;
        while(x!=n+1){
            if(x>n)
                x=(x-n)*2-1;
            else
                x*=2;
            ans++;
        }
        printf("Case #%d:\n%d\n",t,ans);
    }
    
    return 0;
}

 

posted @ 2020-01-26 21:23  StelaYuri  阅读(92)  评论(0编辑  收藏  举报