oj mrJudge
Toggle navigation
  • Login
    • Forget Password
      Login
User Image

Hello, Stranger

Guest
  • Analysis Mode
  • Problems
    • All Problems
    • Latest Problems
  • Join Us Now
  • Registration
  • Contact Us
  • Infomation
  • About
    • Terms of Use
    • Technical Specifications
    • Credits

numberfun Batch , stdin/stdout

Registered Users Only

Please login to utilize this feature.

Do note that this website only supports submissions in C++.

numberfun.html

Problem Description

Gug is having fun with numbers! He starts off with an original number X, and can choose between the following operations:

  1. If X is a multiple of 2, divide X by 2.
  2. If X is a multiple of 3, divide it by 3.
  3. Subtract 1 from X.

Gug repeats this until he is happy, which is when X becomes 0. Given a list of N integers that Gug starts with, determine for each integer Ai, the minimum operations it takes for Gug to be happy.

Input

The first line of input will contain a single integer, N.

The second line of input will contain N integers, representing the array Ai.

Output

The output should contain N lines with one integer each, with the integer on the ith line representing the number of operations it takes for Gug to be happy if he starts with X = Ai.

Limits

Subtask 1 (30%): N = 1, 0 ≤ Ai ≤ 1000000..

Subtask 2 (31%): 1 ≤ N ≤ 105, 0 ≤ Ai ≤ 1000000.

Subtask 3 (39%): 1 ≤ N ≤ 105, 0 ≤ Ai ≤ 30000000.

Subtask 4 (0%): Sample Testcases.

Sample Input 1

5
1 5 3 10 9

Sample Output 1

1
4
2
4
3

Tags

Dynamic Programming

Subtasks and Limits

Subtask Score #TC Time Memory Scoring
130201s256MBMinimum
231411s256MBMinimum
339611s256MBMinimum
4011s256MBMinimum

Judge Compile Command

g++-8 ans.cpp -o numberfun -Wall -Wshadow -static -O2 -lm -m64 -s -w -std=gnu++17 -fmax-errors=512

Accepted Submissions

subIDUserTimeMax Time

Past Submissions

subIDUserTimeScore
mrJudge 09.05.20
Copyright © 2020 mrJudge. All rights reserved.