- 1)))
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%d", &n);
printf("%s\n", (is_power_two(n) ? "YES" : "NO"));
}
return 0;
}
Go reverse, then you can get rid of i
Use popcount(n) == 1
And this code has a bug because loop controller variable is used in scanf inside the loop
Btw is that is_power_two working?
A better implementation of the functions is inline bool is_power_two(int n){ return !(n & (n - 1)); }
Обсуждают сегодня