HDOJ 1339 A Simple Task(简单数学题,暴力)
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(简单数学题,暴力)的更多相关文章
- Codeforces C. A Simple Task(状态压缩dp)
题目描述: A Simple Task time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- HDU-1339 A Simple Task
http://acm.hdu.edu.cn/showproblem.php?pid=1339 正常做法超时,要有点小技巧存在. A Simple Task Time Limit: 2000/1000 ...
- A Simple Task CodeForces - 11D
A Simple Task CodeForces - 11D 题意:输出一个无向图的简单环数量.简单环指无重复边的环.保证图无重边自环. ans[i][j]表示"包含i中的点,以i中第一个点 ...
- [JZOJ5773]【NOIP2008模拟】简单数学题
Description 话说, 小X是个数学大佬,他喜欢做数学题.有一天,小X想考一考小Y.他问了小Y一道数学题.题目如下: 对于一个正整数N,存在一个正整数T(0<T&l ...
- 计数排序 + 线段树优化 --- Codeforces 558E : A Simple Task
E. A Simple Task Problem's Link: http://codeforces.com/problemset/problem/558/E Mean: 给定一个字符串,有q次操作, ...
- A Simple Task
A Simple Task Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- Codeforces 558E A Simple Task (计数排序&&线段树优化)
题目链接:http://codeforces.com/contest/558/problem/E E. A Simple Task time limit per test5 seconds memor ...
- 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 ...
- 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 ...
随机推荐
- 【错误总结之(一)】error LNK2038: 检測到“_ITERATOR_DEBUG_LEVEL”的不匹配项: 值“0”不匹配值“2”
1>cvblob.lib(cvblob.obj) : error LNK2038: 检測到"_ITERATOR_DEBUG_LEVEL"的不匹配项: 值"0&quo ...
- Android Toast 自定义
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&quo ...
- url参数中有+、空格、=、%、&、#等特殊符号的处理
url参数中有+.空格.=.%.&.#等特殊符号的问题解决? 解决办法: 将这些字符转化成服务器可以识别的字符,对应关系如下: URL字符转义 + URL 中+号表示空格 %2B 空格 URL ...
- Android 快速开发系列 打造万能的ListView GridView 适配器
转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/38902805 ,本文出自[张鸿洋的博客] 1.概述 相信做Android开发的写 ...
- Freemarker常用技巧(二)
1 list.break指令<#list sequence as item> ...</#list>tem_index:当前变量的索引值.item_has_next:是否存在 ...
- NOI2015 程序自动分析
/* 十分简单的题面 离散化一下 然后并茶几一下就OK了 跑的死慢 可能还有更优的方法吧 */ #include<iostream> #include<cstdio> #inc ...
- mysql source命令导入sql文件效率分析和索引整理
Query OK, 24918 rows affected (0.90 sec)Records: 24918 Duplicates: 0 Warnings: 0 Query OK, 24923 r ...
- FineUI页面级别的参数配置
Theme: 控件主题,目前支持三种主题风格(blue/gray/access,默认值:blue) Language: 控件语言(en/zh_CN/zh_TW/...,默认值:zh_CN) FormM ...
- Jquery.Sorttable 桌面拖拽自定义
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8&quo ...
- 杂记之web篇
问题1:通过POST方式提交给后台的数据出现了乱码,用部分浏览器测试却是好的. 解决办法: 在web.config文件中加上 <globalization responseEncoding=&q ...