#!/usr/local/bin/python3
# -*- coding: utf-8 -*-
# 476 Number Complement

__author__ = 'Libao Jin'
__date__ = '02/04/2017'

import time

class Solution(object):
    def findComplement(self, num):
        '''
        :type num: int
        :rtype: int
        '''
        number = num
        n = 0
        while number > 0:
            number = int(number / 2)
            n += 1
        m = int(2 ** n - 1)
        complement = num ^ m
        return complement

    def test(self):
        start_time = time.time()
        num = 1
        result = self.findComplement(num)
        end_time = time.time()
        print(result)
        print('Elapsed time: {0:.6f}'.format(end_time - start_time))

if __name__ == '__main__':
    s = Solution()
    s.test()
