博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
zju——Simple Task
阅读量:5111 次
发布时间:2019-06-13

本文共 1362 字,大约阅读时间需要 4 分钟。

原题:

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

 

原码:

#include < stdio.h>    #include < math.h>    int main()    {    int N;    int cases;    int i,j;    int flag;    scanf("%d",&cases);    while(cases--)    {       scanf("%d",&N);       flag =0;       for(i=1;;i+=2)       {        for(j=0;;j++)        {         if( (i*pow(2,j))>N)          break;         if(i*pow(2,j)==N )         {          printf("%d %d\n",i,j);          flag =1;          break;         }        }        if(flag ==1)         break;       }    }    return 0;    }

 

 

转载于:https://www.cnblogs.com/xinyuyuanm/archive/2013/03/27/2985484.html

你可能感兴趣的文章
【ul开发攻略】HTML5/CSS3菜单代码 阴影+发光+圆角
查看>>
IO—》Properties类&序列化流与反序列化流
查看>>
Codeforces 719B Anatoly and Cockroaches
查看>>
关于TFS2010使用常见问题
查看>>
poj2752 Seek the Name, Seek the Fame
查看>>
程序员的数学
查看>>
聚合与组合
查看>>
ionic2+ 基础
查看>>
Screening technology proved cost effective deal
查看>>
Thrift Expected protocol id ffffff82 but got 0
查看>>
【2.2】创建博客文章模型
查看>>
Jsp抓取页面内容
查看>>
大三上学期软件工程作业之点餐系统(网页版)的一些心得
查看>>
可选参数的函数还可以这样设计!
查看>>
[你必须知道的.NET]第二十一回:认识全面的null
查看>>
Java语言概述
查看>>
关于BOM知识的整理
查看>>
使用word发布博客
查看>>
面向对象的小demo
查看>>
微服务之初了解(一)
查看>>