mshereef's blog

By mshereef, history, 3 years ago, In English

I was solving this problem Odd Divisor and when I tested it using the sample test cases it produced the correct output in my IDE, however when I submit the code, it produces a different output with the sample test case and so gives a wrong answer on test 1.

Here's the code:

#include <iostream>
#include <string>
using namespace std;


long t, x;
int main(){


    cin >>t;
    while(t--){
        cin>>x;
        if(x%2==1)cout<<"YES";
        else{
            bool f=false;
            while(x>1){
                if((x/2)%2==1&&(x/2)!=1){
                    f=true;
                    break;
            }
            x/=2;
        }
        if(f)cout<<"YES";
        else cout<<"NO";
    }
    cout<<"\n";
}
return 0;
}

If anyone knows why this is happening, I would really appreciate the help.

  • Vote: I like it
  • 0
  • Vote: I do not like it

| Write comment?
»
3 years ago, # |
  Vote: I like it +3 Vote: I do not like it

use long long instead of long

  • »
    »
    3 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    it worked thank you so much, do you have any idea why that happens though?

    • »
      »
      »
      3 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      If you want to be sure of how large your type is, you can use int64_t instead of long long.