列表

详情


NC25716. Trial of Devil

描述

    As an acmer, Devil Aguin particularly loves numbers. This time, with a sequence consisting of n elements 1∼n initially, Devil Aguin asks you to process the sequence until all the elements in it turn to zero. What you can do in one operation are as following :
    1. Select some elements from the sequence arbitrarily.
    2. Select a positive integer x arbitrarily.
    3. Subtract x from the elements you select.
    It is obvious that there are various methods to make elements of the sequence turn to zero. But Devil Aguin demands of you to use the minimum operations. Please tell him how many operations you will use.

输入描述

    The first line contains an integer number T, the number of test cases.

     of each next T lines contains one integer n(), the number of sequence.

输出描述

For each test case print a number, the minimum number of operations required.

示例1

输入:

2
1
2

输出:

1
2

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

C++14(g++5.4) 解法, 执行用时: 3ms, 内存消耗: 484K, 提交时间: 2019-05-12 13:03:32

#include<bits/stdc++.h>
using namespace std;

int main() {
	int t;
	scanf("%d", &t);
	while (t--) {
		int n;
		scanf("%d", &n);
		printf("%d\n", (int)(log2(n)) + 1);
	}
}

C++11(clang++ 3.9) 解法, 执行用时: 3ms, 内存消耗: 352K, 提交时间: 2019-05-12 12:49:45

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--){
		int x;
		cin>>x;
		cout<<int(log(x)/log(2))+1<<endl;
	}
	return 0;
}

Python3(3.5.2) 解法, 执行用时: 35ms, 内存消耗: 3548K, 提交时间: 2020-04-29 12:53:27

T=int(input())
for i in range(T):
    ans=0
    n=int(input())
    while n:
        ans+=1
        n//=2
    print(ans)

上一题