Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
https://practice.geeksforgeeks.org/contest-problem/sp-range-queries/0/
above is the link for the question.

What I have tried:

I could only get the brute force method for the question. But since the limit are pretty high..i got a TLE as expected.
Posted
Updated 10-Jul-18 22:44pm

It's a contest: so your asking for a solution here is cheating, and we don't help with that.

The idea is that you pity your brain and your skills against other entrants, not mine.
 
Share this answer
 
Comments
Member 13906930 11-Jul-18 4:43am    
the competition is already done, :)
This challenge like any other challenges is to test your ability, you skills at programming.
Quote:
I could only get the brute force method for the question.

There is different levels in brute force. You should show your code.

On 'geeksforgeeks.org', challenges are notoriously difficult and only your knowledge of algorithms and data structures can help you.

Generally speaking, brute force is the first solution one find, then a study of what is useful and what can be removed is the lead to a better solution.
 
Share this answer
 
This is my brute force logic
//
// Created by B Sriman on 10-07-2018.
//

#include <iostream>
using namespace std;

int main() {
    //code
    int t;
    cin>>t;
    while(t--){
        int q;
        cin>>q;
        while(q--){
            int l,r;
            cin>>l>>r;
            int total_count = 0;
            for(int i=l;i<=r;i++){
                int count = 0;
                int j = i;
                while(j){
                    j &= j-1;
                    count++;
                }
                if(count <= 3)
                    total_count++;
            }

            cout<<total_count<<endl;
        }
    }
    return 0;
}
 
Share this answer
 
Comments
Patrice T 11-Jul-18 4:56am    
Use Improve question to update your question.
So that everyone can pay attention to this information.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900