- Check our contribution guidelines in CONTRIBUTING.md
- Star and Fork this repo.
- Clone the repo on your local machine using
git clone https://github.com/{your-username}/python-algorithms.git
. - Create a branch
git checkout -b your_new_branch_name
- Make required changes then add and commit
git add.
git commit -m "your commit message"
- Push your changes
git push origin your_new_branch_name
- Merge and send a Pull-request.
Referance: Competetive programming with python
def sum_total(n):
return int(n*(n+1)/2)
def gcd(a,b):
if a == 0:
return b
return gcd(b%a,a)
def lcm(a,b):
prod = a*b
hcf = gcd(a,b)
return prod//hcf
if n&1 == 1:
print('odd')
else:
print('even')
def multpow(x,y):
return x<<y # x*(2^y)
def divpow(x,y):
return x>>y # x/(2^y)
def ispow(n):
if n <= 0:
return False
x = n
y = not(n & (n-1))
return x and y
def cntbits(n):
cnt = 0
while n:
cnt += 1
n = n & (n-1)
return cnt
def inttobin(n):
return str(bin(n))[2:]
def bintoint(m):
return int(m,2)
check which number occurs once(or odd number of times/doesn't has it's unique identical element) in an array:O(n)
def checkpair(arr): # n -> aray
temp = arr[0]
for i in range(1,len(arr)):
temp = temp ^ arr[i]
return temp