- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Program to find multiple of n with only two digits in Python
Suppose we have a number n. We have to find the least positive value x such that x is made up of only two digits 9's and 0's, and x is multiple of n.
So, if the input is like n = 26, then the output will be 90090.
To solve this, we will follow these steps −
- m := 9
- x := 1
- while m is not divisible by n, do
- x := x + 1
- m := replace all 1s with 9s in the binary form of x
- return m as integer
Example
Let us see the following implementation to get better understanding −
def solve(n): m = 9 x = 1 while m % n != 0: x += 1 m = int(bin(x)[2:].replace('1','9')) return m n = 26 print(solve(n))
Input
26
Output
90090
Advertisements