#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

  • @ 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-16 0:54:12
          #include <stdio.h>
          #include <math.h>
          int main()
          {   int m,i,j,ret;
              long long sz;
              scanf("%d",&m); 
          for(i=1;i<=m;i++)
          {ret=0;
          	scanf("%lld",&sz);
          	for(j=0;pow(2,j)<=sz;j++)
          	{
          		if(pow(2,j)==sz)
          		{
          			ret=1;
          	    }		
          	}
          if(ret==1)
            {
             printf("YES\n");
            }
          else
            {
             printf("NO\n");
            }			
          } 
          	return 0;
          }
          
      • @ 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