Hackerearth | Odd Divisors

This problem is available on HackerEarth. Solution: def square(x,M):
x%=M
return x*x % M

t = int(input())
while t>0:
t-=1
n,M = map(int,input().split(' '))
sum_= 0
while n:
sum_= (sum_ + square(n//2 + n % 2, M)) % M
n //= 2
print(sum_%M) Happy Coding!
Follow us on Instagram @programmersdoor
Join us on Telegram @programmersdoor

Please write comments if you find any bug in the above code/algorithm, or find other ways to solve the same problem.
Follow Programmers Door for more.
#blog #interview #placement #learn #computer #science

        Contact Us

programmersdoor@gmail.com

  • LinkedIn
  • Facebook
  • Instagram

©2023 by Programmers Door