hdu1339
来源:互联网 发布:大数据一体机 编辑:程序博客网 时间:2024/05/19 00:41
A Simple Task
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3857 Accepted Submission(s): 2113
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1339Problem 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.
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.
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.
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
124
Sample Output
3 3解题思路:题意就是给你n,输出满足式子n = o * 2 ^ p的o和p。刚开始暴力(明知道超时····),果然超了····然后看看式子····果断用数学构造····构造出来后很简单,就是不断地把n除以2,除的次数就是p,最后知道不能除为止,此时的n就是o。完整代码:#include <functional>#include <algorithm>#include <iostream>#include <fstream>#include <sstream>#include <iomanip>#include <numeric>#include <cstring>#include <climits>#include <cassert>#include <complex>#include <cstdio>#include <string>#include <vector>#include <bitset>#include <queue>#include <stack>#include <cmath>#include <ctime>#include <list>#include <set>#include <map>using namespace std;#pragma comment(linker, "/STACK:102400000,102400000")typedef long long LL;typedef double DB;typedef unsigned uint;typedef unsigned long long uLL;/** Constant List .. **/ //{const int MOD = int(1e9)+7;const int INF = 0x3f3f3f3f;const LL INFF = 0x3f3f3f3f3f3f3f3fLL;const DB EPS = 1e-9;const DB OO = 1e20;const DB PI = acos(-1.0); //M_PI;int main(){ #ifdef DoubleQ freopen("in.txt","r",stdin); #endif int d; scanf("%d",&d); while(d--) { int n; scanf("%d",&n); int cnt = 0; while(n % 2 == 0) { n /= 2; cnt ++; } printf("%d %d\n",n , cnt); }}
0 0
- hdu1339
- hdu1339
- hdu1339
- hdu1339
- HDU1339:A Simple Task
- hdu1339-A Simple Task
- C++中函数指针的使用
- 再谈留学申请选校地理位置的优势
- PonyDebugger 手动安装
- Asp.Net alert弹出提示信息的5种方法
- 简单的 Nova REST API 实现程序
- hdu1339
- Android在onCreate()中获得控件尺寸
- SharePoint2010 Feature功能开发——为SharePoint的ECB菜单(列表项或文档的操作菜单项)添加自定义菜单栏项目
- Android中ListView与CheckBox结合----多选与记录
- 第六届深圳国际物联网和智慧中国博览会(2014)总结
- 赤脚跑步只是一个骗局
- mdev自动挂载sd卡
- hdu 4035 概率DP 成都网赛
- HDU 3718 Similarity(二分图最优匹配)