4 solutions

  • 3
    @ 2025-9-24 19:01:54
    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
    	//if(n==pow(2,x)+pow(2,y))
    	int l,r;
    	cin>>l>>r;
    	int ans=0;//表示幂和数的个数 
    	for(int n=l;n<=r;n++) //一定先有n,再有(x,y)保证(n)只出现一次 
    	{
    		int cnt=0;//表示当前pow(2,x)+pow(2,y)==n的个数
    		for(int x=0;pow(2,x)<=n;x++)
    		{
    			for(int y=0;pow(2,y)<=n;y++)
    			{
    				if(pow(2,x)+pow(2,y)==n)
    				{
    					cnt++; //说明多了一组pow(2,x)+pow(2,y)==n, 
    				}
    			}
    		} 
    		if(cnt!=0) //说明至少存在一组x,y满足幂和数的条件 
    		{
    			ans++;
    		}
    	}
    	cout<<ans;
    	return 0;
    }
    
    
    
    
    • 0
      @ 2025-11-8 15:55:38
      #include<bits/stdc++.h>
      using namespace std;
      int main(){
      	int l,r;
      	cin>>l>>r;
      	int cnt=0;
      	for(int i=l;i<=r;i++){
      		bool a=0;
      		for(int x=0;x<=15;x++){
      			for(int y=0;y<=15;y++){
      				if(pow(2,x)+pow(2,y)==i){
      					a=1; 
      				}
      			}
      		}
      		if(a==1){
      			cnt++;
      		}
      	}
      	cout<<cnt;
      	return 0;
      }
      
      • 0
        @ 2025-11-2 16:00:48
        #include<bits/stdc++.h>
        using namespace std;
        int l,r;
        int main(){
        	cin>>l>>r;
        	int cnt=0;
        	for(int k=l;k<=r;k++){
        		bool st=0;
        		for(int x=0;x<=15;x++){
        			for(int y=0;y<=15;y++){
        				if(pow(2,x)+pow(2,y)==k){
        					st=1;
        				}
        			}
        		}
        		if(st==1){
        			cnt++;
        		}
        	}
        	cout<<cnt;
        
        	return 0;
        }
        
        ```language
        
        
        • -1
          @ 2025-11-8 15:55:58

          • 1

          Information

          ID
          2806
          Time
          1000ms
          Memory
          256MiB
          Difficulty
          1
          Tags
          # Submissions
          44
          Accepted
          15
          Uploaded By