Problem Description
Given a positive integer n and the odd integer o and the nonnegative integer p such that n = o2^p.
Example
For n = A, o = 3 and P = 3.
Task
Write a program which for each data set:
Reads a positive integer n,
Computes the odd integer o and the nonnegative integer p such that n = o2^p,
Writes the result.
Input
The first line of the input contains exactly one positive an integer d equal to the number of data sets, 1 <= d <= 10. The data sets follow.
Each data set consists the exactly one line containing exactly one integer n, 1 <= n <= 10^6.
Output
The output should consists of exactly d lines, one line for each data set.
Line I, 1 <= i <= D, corresponds to the i-th input and should contain II integers o and P separated by a single spa Ce such that n = o2^p.
Sample Input
1
24
Sample Output
3 3
Ideas:
is a formula: n = o*2^p.
n is the input, and O and P are required by us.
It is important to note that O must be an odd number!
0<=p's.
Import Java.util.Scanner; Public classmain{ Public Static void Main(string[] args) {Scanner SC =NewScanner (System.inch);intt = Sc.nextint (); while(t-->0){intn = sc.nextint ();intA=0;into=0; for(intp=0;p <n;p++) {a= (int) Math.pow (2, p);if(a>n) { Break; }if(n%a==0) {o=n/a;if(o%2==0){Continue; } a=p; Break; }} System. out. println (o+" "+A); } }}
Hdoj 1339 A Simple Task (math problem, violence)