Same code works on C++ but not in python

same code works in c++ but not in python 3.

if you’re talking about literally the same code, is not strange at all…Python interpreter is not able to understand c++ code.

Otherwise, how could we help without the codes?

6 Likes

is it throwing some error?

no bro not literally :expressionless:

its giving wrong answer however the code works for subtask in python but not fully hence my answer is partially accepted in python but fully accepted in c++

Paste the code bro! (And if it is from live contest, just ask after the contest ends.)

i will paste code after the contest then

Check output of both codes for some random input

its same

If the problem is WA and not TLE, then there must be difference in outputs for some input

since in python there is no issue of large integers so issue might be in usage of list ,modulus etc… check it again

1 Like

Since the contest is now over i am uploading my codes kindly have a look and tell me where I went a wrong

Working C++ Code:-

https://www.codechef.com/viewsolution/34280955

Partially working Python code:-

https://www.codechef.com/viewsolution/34281082

using namespace std;

int main()
{
    int t;
    long int n;
    ios::sync_with_stdio(false);
    cout.tie(NULL);
    cin.tie(NULL);
    cin>>t;
    while(t--)
    {
        cin>>n;
        while(n%2==0)
        {
            n /= 2;
        }
        
        cout<<n/2<<endl;
        
    }
    return 0;
}```




```t = int(input())
while t > 0:
    ts = int(input())
    while ts % 2 == 0:
        ts /= 2
    print(int(ts / 2))
    t -= 1

we happen to write a code after 10 days of rigorous efforts for a complex problem in python and It shows TLE because the problem setter didn’t manage to put efforts in doing things for python submissions ! and A 6 star makes fun out of it
(PS UPLOAD THE CODES Then we can see things brother )

1 Like

you are not using floor division in python try using // instead of / for division

Use floor division instead of standard division( ’ // ’ instead of ‘/’)

1 Like

int() takes care of it no need for //

bro he meant inside the while loop

/= should be changed

1 Like

the loop is entered only when the number is even so no need

and when you enter in the loop constantly is depending on the / division not floor division which is needed ! try using it why are you being so stubborn on that operator bro !!

1 Like