A. Help Help !!

0

0 votes
Recursion, Basic Math, Dynamic Programming
Problem

Arun is Varun's maths teacher. He gives him a function F(X), which is defined as follows :

  1. If X is a multiple of 2, then F(X) will be F(X2).
  2. If X is a multiple of 3, then F(X) will be F(X3).
  3. If X is a multiple of both 2 and 3, then F(X) will be F(X2) + F(X3).
  4. Else F(X) will be equal to X.

Now, Arun gives him Q queries and in each query, a value of X is given. Varun's task is to solve for F(X). Since there are many queries help Varun to pass this assignment.

Output can be large, return F(X)mod1000000007.

Input format

First-line contains Q - the number of queries.

Next Q lines contain an integer X.

Output format

Print Q lines each contain the value of F(X).

Constraints

1Q1051X1018

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

For X=1,F(X)=1. Because 1 is not multiple of 2 and 3.

For X=4,F(4)=F(4/2)=F(2/2)=F(1)=1. Because 4 is multiple of 2.

For X=6,F(6)=F(3)+F(2)=F(3/3)+F(2/2)=F(1)+F(1)=2. Because 6 is multiple of both 2 and 3.

Editor Image

?