FIVE - Editorial

PROBLEM LINKS:

practice

contest

Difficulty:

Easy

Pre-requirements:

Decimal-Octal conversion

Problem:

Find the frequence of digit 5 in the octal representation of the given decimal number N.

1<=N<=1018

Explanation:

The digits in the octal representation can be easily obtained by continously dividing by 8 and finding the remainder till N becomes Zero. Remainder in each iteration represents a digit in octal representation.

Use a count variable to count the number of times the remainder is 5

complexity: O(log(N))

Authors Solution:

can be found here