I am not familiar with Python but it seems that you are using file for input. You should read from the standard input and output to the standard output.
I actually am using standard input. It reads from an input file on my computer (for testing), but if that file doesnāt exist (when I submit) it uses raw_input() instead. Iāve tested this method on the codechef judge and it works for other problems, so I donāt understand why it gets runtime error now.
That doesnāt make senseā¦ bin is a built-in function, how could it not be defined? I thought it must be something with the input because this solution CodeChef: Practical coding for everyone got accepted.
You will be angry, but your code works - CodeChef: Practical coding for everyone , is there problem with whitespace, PY is āwhitespace sensitiveā, isnāt it?
That link doesnāt work, but I see that you got my solution accepted. So I tried it myself and got runtime error CodeChef: Practical coding for everyone. (this is the exact same code that you got accepted, right?) And yeah, python is whitespace-sensitive, but I donāt see how that could be the problem because the solution I posted above got accepted. Something really weird is going onā¦
for _ in range(int(input())):
p = int(input())
c = 0
if p<=2048:
print(bin(p).replace("0b","").count('1'))
continue
else:
c = p//2048
p = p - 2048*(c)
print(c + bin(p).replace("0b","").count('1'))
int main(){
int t;
cin >> t;
while(tā){
long long n,flag = 0;
cin >> n;
long long cnt = 0;
while(n > 2048){
n = n - 2048;
cnt++;
}
while(n != 0){
if(n & 1){
flag++;
}
n >>= 1;
// cout << n << " ";
}
flag = flag + cnt;
cout << flag << endl;
}
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long int t;
cin>>t;
while(tā)
{
long long int a;
cin>>a;
auto k=__builtin_popcount(2048);
if(a > 2048)
{
auto x=a/2048;
auto y=a%2048;
if(y==0)
{
cout<<xk(X multiplied by k)<<endl;
}
else
{
auto sum=xk;
sum+=__builtin_popcount(y);
cout<<sum<<endl;
}
}
else
{
cout<<__builtin_popcount(a)<<endl;
}
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
cin >> t;
while (t--)
{
int n;
cin >> n;
int count = 0;
for (int i = 11; i >= 0; i--)
{
int d = pow(2, i);
int num = n % d;
if (num == 0)
{
count += (n / d);
break;
}
else
{
if (n != num)
count++;
n %= d;
}
}
cout << count << endl;
}
return 0;