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 = 24, 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 integer d equal to the number of data sets, 1 <= d <= 10. The data sets follow.

Each data set consists of 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 two integers o and p separated by a single space such that n = o2^p.

Sample Input

1

24

Sample Output

3 3

思路:

就是一个公式: n = o*2^p.

n是输入的,o和p是我们需要求的。

需要注意的是o必须是奇数!

0<=p的。

import java.util.Scanner;

public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0){
int n = sc.nextInt();
int a=0;
int o=0;
for(int p=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(简单数学题,暴力)的更多相关文章

  1. Codeforces C. A Simple Task(状态压缩dp)

    题目描述:  A Simple Task time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  2. HDU-1339 A Simple Task

    http://acm.hdu.edu.cn/showproblem.php?pid=1339 正常做法超时,要有点小技巧存在. A Simple Task Time Limit: 2000/1000 ...

  3. A Simple Task CodeForces - 11D

    A Simple Task CodeForces - 11D 题意:输出一个无向图的简单环数量.简单环指无重复边的环.保证图无重边自环. ans[i][j]表示"包含i中的点,以i中第一个点 ...

  4. [JZOJ5773]【NOIP2008模拟】简单数学题

    Description       话说, 小X是个数学大佬,他喜欢做数学题.有一天,小X想考一考小Y.他问了小Y一道数学题.题目如下:      对于一个正整数N,存在一个正整数T(0<T&l ...

  5. 计数排序 + 线段树优化 --- Codeforces 558E : A Simple Task

    E. A Simple Task Problem's Link: http://codeforces.com/problemset/problem/558/E Mean: 给定一个字符串,有q次操作, ...

  6. A Simple Task

    A Simple Task Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  7. Codeforces 558E A Simple Task (计数排序&&线段树优化)

    题目链接:http://codeforces.com/contest/558/problem/E E. A Simple Task time limit per test5 seconds memor ...

  8. Codeforces Round #312 (Div. 2) E. A Simple Task 线段树

    E. A Simple Task 题目连接: http://www.codeforces.com/contest/558/problem/E Description This task is very ...

  9. Codeforces Round #312 (Div. 2) E. A Simple Task 线段树+计数排序

    题目链接: http://codeforces.com/problemset/problem/558/E E. A Simple Task time limit per test5 secondsme ...

随机推荐

  1. IBinder对象在进程间传递的形式(一)

    命题 当service经常被远程调用时,我们经常常使用到aidl来定一个接口供service和client来使用,这个事实上就是使用Binder机制的IPC通信.当client bind servic ...

  2. Bitmap基本概念及在Android4.4系统上使用BitmapFactory的注意事项

    本文首先总结一下Bitmap的相关概念,然后通过一个实际的问题来分析设置BitmapFactory.options的注意事项,以减少不必要的内存占用率,避免发生OOM. 一. Bitmap的使用tri ...

  3. Java基础知识强化96:Calendar类之获取任意年份的2月有多少天的案例

    1. 分析: (1)键盘录入任意的年份 (2)设置日历对象的年月日            年:就是(1)输入的数据            月:是2(3月份)            日:是1  (3)把 ...

  4. linux 网络状态工具ss命令

    ss命令用于显示socket状态. 他可以显示PACKET sockets, TCP sockets, UDP sockets, DCCP sockets, RAW sockets, Unix dom ...

  5. linux命令chown修改文件所有权

      Changing User Ownership To apply appropriate permissions, the first thing to consider is ownership ...

  6. css10定位属性

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  7. python的运算符

    #coding=utf-8#"+"两个对象相加#两个数字相加a=7+8print a #两个字符串相加b="GOOD"+"JOB"print ...

  8. ASP.NET-FineUI开发实践-6

    FineUI4.1.0更新,传说的V4版稳定版,很多人也从3.0+升级了,接着又连续更新了几次,现在是V4.1.3 2014-09-09日更新的.更新的挺快,感觉跟不上节奏,我很欣慰,看来开原版还是靠 ...

  9. hdu 2104

    #include <iostream> using namespace std; int gcd(int a,int b) { return (b?gcd(b,a%b):a); } int ...

  10. JAVA彩色图片变灰处理

    File file = new File("F:/firefox.png"); File destFile = new File("F:/pic/" + Sys ...