A Simple Task

我不是女神ヾ 2022-08-18 02:22 317阅读 0赞

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. 1
  2. 24

示例输出

  1. 3 3

提示

zoj1382有链接提示的题目请先去链接处提交程序,AC后提交到SDUTOJ中,以便查询存档。

来源

面向对数据结构和算法不太懂的同学

  1. #include<stdio.h>
  2. #include<math.h>
  3. int main()
  4. {
  5. int i,j,n,m,k,t;
  6. scanf("%d",&t);
  7. while(t--)
  8. {
  9. scanf("%d",&n);
  10. for(i=1;i<=n;i+=2)
  11. for(j=0;i*(pow(2,j))<=n;j++)
  12. if(i*(pow(2,j))==n)
  13. printf("%d %d\n",i,j);
  14. }
  15. }

发表评论

表情:
评论列表 (有 0 条评论,317人围观)

还没有评论,来说两句吧...

相关阅读

    相关 HDU(1851) A Simple Game (博弈)

    任给N堆石子,两人轮流从任一堆中任取(每次只能取自一堆),规定每方每次最多取K颗,取最后一颗石子的一方获胜.问先取的人如何获胜? 巴什博奕和尼姆博弈的综合。 令Bi=Mi