- 2的幂次方
#P1043. 2的幂次方
- 2021-10-15 19:54:38 @
#include<stdio.h>
#include<math.h>
int main()
{
int a,m;
scanf("%d",&a);
while(a--)
{
scanf("%d",&m);
int i;
i=m/2;
if(m==pow(2,i))
printf("YES\n");
else
printf("NO\n");
}
return 0;
}
这个题long long的范围怎么解决?
6 comments
-
MuQuanyu LV 6 @ 2022-3-28 21:48:27
我是 直接 全用 long long 类型了。
#include <iostream> using namespace std; int main(void) { long long n; cin >> n; for (int i = 0; i < n; ++i) { long long a; cin >> a; long long temp = 1; bool flag = false; while (temp <= a) { if (temp == a) { flag = true; break; } temp <<= 1; } if (flag) { cout << "YES" << endl; } else { cout << "NO" << endl; } } return 0; }
-
2021-10-16 0:54:43@
不是最优,仅供参考
-
2021-10-16 0:38:14@
}
-
2021-10-15 20:07:44@
#include<stdio.h> #include<math.h> int main(){ long long a,m; scanf("%lld",&a); while(a--){ scanf("%lld",&m); int i; i=m/2; if(m==pow(2,i)) printf("YES\n"); else printf("NO\n"); } return 0; }
-
2021-10-15 20:06:49@
2
-
2021-10-15 20:05:20@
1
- 1
Information
- ID
- 47
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 8
- Tags
- # Submissions
- 1435
- Accepted
- 225
- Uploaded By