top of page

Hackerearth | Odd Divisors

Writer's picture: Lokendra VedLokendra Ved

Updated: Jun 16, 2020

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

15 views0 comments

Recent Posts

See All

Comments


bottom of page