#include<stdio.h> #include<algorithm> using namespace std; int main(void) { int T,n,m; int val=0; while(scanf("%d",&T)!=EOF) { while(T--) { scanf("%d%d",&n,&m); m=min(m,31); val=n/(1<<m); while(n!=1||n!=2) { n%=(1<<m); m=m-1; val+=n/(1<<m); if(n==0)break; } printf("%d\n",val); } } return 0; }
时间: 2024-10-19 16:34:30