您的位置:首页 > 编程语言 > C语言/C++

山东理工大学ACM平台题答案关于C语言 1063 A Simple Task

2013-12-15 16:03 225 查看

A Simple Task


Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^

题目描述

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.

输入

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.

输出

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.

示例输入

1
24


示例输出

3 3



一个简单的任务Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^时间限制:1000MS内存限制:65536k有疑问点这里^ _ ^?题目描述题目描述Given a positive integer n and the odd integer o and the nonnegative integer p such that n = o2^p.给出一个正整数n和奇整数和非负整数p,n = O2 ^ P.Example的例子For n = 24, o = 3 and p = 3. 对于n = 24,O = 3和P = 3。Task任务Write a program which for each data set: 写一个程序,为每个数据集:reads a positive integer n,读入一个正整数n,computes the odd integer o and the nonnegative integer p such that n = o2^p, 计算奇整数和非负整数p,n = O2 ^ P,writes the result.结果写入。输入输入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.输入的第一行包含一个正整数d等于数据集的数目,1≤d≤10。数据集的后续。Each data set consists of exactly one line containing exactly one integer n, 1 <= n <= 10^6.每个数据集由一行包含一个整数N,1≤n≤10 ^ 6。输出输出The output should consists of exactly d lines, one line for each data set.输出应完全由D线,一条线为每个数据集。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.我行,1<=我< = D,对应于第i输入应包含两个整数,O和P由一个单一的空间,N = O2分离^ P.示例输入示例输入1124示例输出24示例输出3 33 3

#include <stdio.h>

int main()

{

int i, n, k;

scanf("%d", &i);

while (i--){

scanf("%d", &n);

k = 0;

while (1){

if ((n&1) != 0) break;

n >>= 1;

k++;

}

printf("%d %d\n", n, k);

}

return 0;

}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐