Hdoj 1339 A Simple Task (math problem, violence)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.