6 solutions

  • 0
    @ 2026-7-9 14:56:43
     #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
        int a;
        cin>>a;
        if(a%2==1)   
        {
            cout<<"-1";
        }
        else
        {
            for(int i=a;i>=1;i--)
            {
                if(pow(2,i)<=a)
                {
                    cout<<(int)pow(2,i)<<" ";
                    a-=pow(2,i);
                }
            }
        }
        return 0; 
    }
    
    • 0
      @ 2026-7-7 14:43:33
      #include<bits/stdc++.h>
      using namespace std;
      int main()
      {
          int n;
          cin>>n;
          int t=n;
          if(n%2==1) {
              cout<<-1;
              return 0;
          }
          while(t>1){
              int mx=-1;
              for(int i=1;i<=t;i++){
                  if(pow(2,i)>t){
                      mx=i-1;
                      break;
                  }
              }
              cout<<int(pow(2,mx))<<' ';
              t=t-pow(2,mx);
          }
          return 0;
      }
      
      • 0
        @ 2026-7-7 14:20:22
        #include<bits/stdc++.h>
        using namespace std;
        int main()
        {
            int n;
            cin>>n;
            if(n%2==1) cout<<-1;
            else for(int i=30;i>=1;i--) if(n>>i&1) cout<<(1<<i)<<" ";
            return 0;
        }
        
        • 0
          @ 2026-6-20 10:50:11
          #include <bits/stdc++.h>
          using namespace std;
          
          int main()
          {
          	int n;
          	cin>>n;
          	if(n&1)
          	{
          		cout<<"-1";
          	}
          	else
          	{
          		bitset<32> a(n);
          		for(int i=31;i>=0;i--)
          		{
          			if(a[i]==1)
          			{
          				cout<<(1<<i)<<" ";
          			}
          		}
          	}
          	return 0;
          }
          • 0
            @ 2026-1-3 9:42:59
            #include<bits/stdc++.h>
            using namespace std;
            int main()
            {
            	int n;
            	cin>>n;
            	bitset<32> a(n);
            	if(a[0]==1)
            	{
            		cout<<-1;
            	}
            	else
            	{
            		for(int i=31;i>=0;i--)
            		{
            			if(a[i]==1)
            			{
            				cout<<(1<<i)<<" ";
            			}
            		}
            	}
            	return 0;
            }
            
            
            • -2
              @ 2024-10-16 20:18:16
              #include<bits/stdc++.h>
              using namespace std;
              int main()
              {
              int n;
              cin>>n;
              if(n%2==1)
              {
              	cout<<-1;
              }
              else
              {
              	for(int i=30;i>=1;i--)
              	{
              		if(n>>i&1)
              		{
              			cout<<(1<<i)<<" ";
              		}
              	 } 
               } 
              return 0;
              }
              
              
              
              • 1

              Information

              ID
              125
              Time
              1000ms
              Memory
              256MiB
              Difficulty
              3
              Tags
              (None)
              # Submissions
              96
              Accepted
              37
              Uploaded By