zoukankan      html  css  js  c++  java
  • HDU1339--A Simple Task

    A Simple Task
    Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 3063 Accepted Submission(s): 1683


    Problem 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.


    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


    Source
    Central Europe 2001, Practice


    Recommend
    Ignatius.L

     1 #include<cstdio>
     2 #include<cmath>
     3 #include<cstring>
     4   
     5 int f[100];
     6   
     7 int main()
     8 {
     9     int ans=2,i;
    10     f[1]=2;
    11     f[0]=1;
    12     for(i=2;;i++)
    13     {
    14         f[i]=f[i-1]*2;
    15         if(f[i]>1e7)
    16         {
    17             break;
    18         }
    19     }
    20     int d;
    21     scanf("%d",&d);
    22     while(d--)
    23     {
    24         int num,temp;
    25         scanf("%d",&num);
    26         for(i=0;;i++)
    27         {
    28             if(num>=f[i])
    29             {
    30                 if(num%f[i]==0)
    31                 {
    32                     temp=num/f[i];
    33                     if(temp%2!=0)
    34                     {
    35                         break;
    36                     }
    37                 }
    38             }
    39             else
    40                 break;
    41         }
    42         printf("%d %d
    ",temp,i);
    43     }
    44     return 0;
    45 }
    View Code
  • 相关阅读:
    Spring session redis
    HttpClient Post Form data and get Response String
    compareTo & toString
    Zookeeper 脑裂
    Maven的HTTP代理设置
    Linux 硬件信息
    [Redis] RDB & AOF
    真实场景中WebRTC 用到的服务 STUN, TURN 和 signaling
    推荐一个VS2015 插件 Favorite Documents
    笔记 Activator.CreateInstance(Type)
  • 原文地址:https://www.cnblogs.com/zafuacm/p/3185225.html
Copyright © 2011-2022 走看看