猜数字
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5012 Accepted Submission(s):
3415
Problem DescriptionA有1数m,B来猜.B每猜一次,A就说”太大”,”太小”或”对了” 。
问B猜n次可以猜到的最大数。 Input第1行是整数T,表示有T组数据,下面有T行
每行一个整数n (1 ≤ n ≤ 30) Output猜n次可以猜到的最大数 Sample Input213 Sample Output17 题解:这种猜数字的原理跟二分类似,每次对半折,要想确保第n次一定能猜对并且最大,就是求2的n次方减一
#include<stdio.h>
#include<string.h>
#include<math.h>
#define LL long long
int main()
{
int t;
LL n;
scanf("%d",&t);
while(t--)
{
scanf("%lld",&n);
LL ans=pow(2,n)-1;
printf("%lld\n",ans);
}
return 0;
}