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

本文介绍了一种通过程序计算特定正整数n的奇数部分o及非负指数p的方法,使得n可以表示为o乘以2的p次方的形式。文章提供了完整的代码示例,演示如何读取输入数据并输出计算结果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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.

示例输入

示例输入

1

1

24示例输出

24示例输出

3 3

3 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;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值