求解一道C++题,先谢谢了!

来源:百度知道 编辑:UC知道 时间:2024/06/18 18:44:18
Given a positive integer n, find the odd integer o and the non-negative integer p such that n=o2p.
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 non-negative integer p such that n=o2p,
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 ≤ 106.

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=o2p.

Sample Input

1
24

Sample Output

3 3
n=2的p次幂
如有一个正整数 n ,找奇数的整数 o 和非负整数 p 以致于 n=o 2 p。

不好意思刚才有一个地方写错了j=j+2而不是j++
#include<stdio.h>
main()
{
int a[12],i=0,j,k;
printf("Sample input:\n");
scanf("%d",a+i);
i++;
while(i<=a[0])
{
scanf("%d",a+i);
i++;
}
a[i]=-1;
printf("Sample output:\n");
for(i=1;i<=a[0];i++)
{
if((a[i]/2)==((a[i]-1)/2))
printf("%d %d\n",a[i],0);
else
{
for(j=1;j<=(a[i]/2);j=j+2)
{
for(k=1;k<7;k++)
{
if(a[i]==(j<<k))
printf("%d %d\n",j,k);
}
}
}
}
}

能把这个转为汉语言吗?如果只是想知道问题补充的答案的话,我建意在知道里有个人与你问的一样,不过我现在觉得你好像拿的是ACM的试题,可没那么简单,