[CodeForces - 950D]A Leapfrog in the Array(思维)

Description

题目地址: Codeforces

Solution

对于一个询问q,如果q是奇数,那么答案就是(q-1)/2

否则将不断q=q/2+n即可

Code

#include <cstdio>
long long n,x;
int q;
int main(){
	scanf("%I64d%I64d",&n,&q);
	while(q--){
		scanf("%I64d",&x); 
		while(!(x&1)) x=(x>>1)+n;
		printf("%I64d\n",(x+1)>>1);
	}
	return 0;
}
posted @ 2018-03-10 09:01  void_f  阅读(604)  评论(0编辑  收藏  举报