3 solutions

  • 3
    @ 2024-12-5 13:17:02
    #include <bits/stdc++.h>
    using namespace std;
    
    int main()
    {
    	int n;
    	
    	while(cin >> n) 
    	{
    		while(n)
    		{
    			if(n%2 == 1&&n != 1)
    			{
    				cout << "no" << endl;
    				break;
    			}
    			else
    			if(n == 1)
    			{
    				cout << "yes" << endl;
    				break;
    			}
    			else
    			{
    				n/=2;
    			}
    		}
    	}
    	return 0;
    }
    
    • 0
      @ 2024-12-6 18:50:43
      #include<bits/stdc++.h>
      
      using namespace std;
      int main(){
      	int n;
      	while(cin>>n){
      		int cnt=0;
      		int c=0,k=1;
      		while(cnt<n){
      			cnt=(k<<c);//1*(2^c)快速计算冥
      			c++; 
      		}
      		if(cnt==n)cout<<"yes"<<'\n';
      		else cout<<"no"<<'\n';
      	}
      	//位运算非正统写法
      	
      	return 0;
      }
      
      • -1
        @ 2024-12-13 19:50:08
        # include<bits/stdc++.h>
        using namespace std;
        void in(int i){
        	int x=true;
        	while(i>1){
        		if(i%2==1){
        			x=false;
        			break;
        		}
        		i/=2;
        	}
        	if(x)cout<<"yes\n";
        	else cout<<"no\n";
        }
        int main(){
        	int x;
        	while(cin>>x)in(x);
        	return 0;
        }
        
        • 1

        Information

        ID
        1141
        Time
        1000ms
        Memory
        1MiB
        Difficulty
        7
        Tags
        # Submissions
        158
        Accepted
        31
        Uploaded By