138602025-01-09 00:00:1442Autókódoláspython3Partially correct 48/5017ms3208 KiB
n=N=int(input())
p=-1
c=0
while n%2==0:
 n//=2
 c+=1
b=bin(n)[2:]
T=b.count('1')
n+=1
t=bin(n)[2:].count('1')
n*=2**c
x=1
for i in range(T-t):
 n+=x
 x*=2
if b+c*'0'!=T*'1':
 if N%2==0:
  c=0
  while N%2==0:
   N//=2
   c+=1
  N//=2
  N*=2
  N*=2
  N+=1
  N*=2**(c-1)
  p=N
 else:
  c=0
  while N%2==1:
   N//=2
   c+=1
  d=0
  while N%2==0:
   N//=2
   d+=1
  N//=2
  N*=2
  for j in range(c+1):
   N*=2
   N+=1
  for j in range(d-1):
   N*=2
   p=N
print(p)
print(n)
SubtaskSumTestVerdictTimeMemory
base48/50
1Accepted0/016ms3124 KiB
2Accepted0/016ms3124 KiB
3Accepted2/216ms3128 KiB
4Accepted2/216ms3124 KiB
5Accepted2/216ms3124 KiB
6Accepted2/216ms3168 KiB
7Accepted2/216ms3208 KiB
8Accepted4/416ms3084 KiB
9Partially correct2/417ms3144 KiB
10Accepted4/416ms3008 KiB
11Accepted4/414ms3132 KiB
12Accepted4/416ms3040 KiB
13Accepted4/416ms3080 KiB
14Accepted4/416ms3008 KiB
15Accepted4/414ms3068 KiB
16Accepted4/416ms2952 KiB
17Accepted4/414ms3124 KiB