We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Hiring developers?
  1. Prepare
  2. Algorithms
  3. Dynamic Programming
  4. Divisible Numbers

Divisible Numbers

Problem
Submissions
Leaderboard
Discussions
Editorial

Given an integer, , find the smallest integer such that is divisible by (i.e., is a factor of ) and satisfies the following properties:

  • must not contain zeroes in its decimal representation.
  • The sum of 's digits must be greater than or equal to the product of 's digits.

Given , find and print the number of digits in 's decimal representation.

Input Format

A single integer denoting .

Constraints

  • is not divisible by .

Time Limits

  • The time limits for this challenge are available here.

Output Format

Print the number of digits in the decimal representation of the smallest possible .

Sample Input 0

1

Sample Output 0

1

Explanation 0

is evenly divided by , doesn't contain any zeroes in its decimal representation, and the sum of its digits is not less than the product of its digits. Thus, we print the number of digits in (which also happens to be ) as our answer.

Sample Input 1

9

Sample Output 1

1

Explanation 1

is evenly divided by , doesn't contain any zeroes in its decimal representation, and the sum of its digits is not less than the product of its digits. Thus, we print the number of digits in , which is , as our answer.

Author

dsoboliev

Difficulty

Expert

Max Score

100

Submitted By

2882

Need Help?


View discussions
View editorial
View top submissions

rate this challenge

MORE DETAILS

Download problem statement
Download sample test cases
Suggest Edits
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy