列表

详情


NC207575. SumoandLuxuryCar

描述

As we all know, Sumo has a lot of luxury cars, Maserati, Porsche, Lincoln, and so on. Countless cars are parked in his garage. He is worried about what kind of car he drives every day. Can you help him?

Sumo has a total of n cars. Every day, he will choose any number of cars from the n cars (the number of cars cannot be 0) to form a team, and then choose one from this team to drive himself. How many options are there?

If the selected team set is different or the car he chooses is different, it is considered to be two different plans.

输入描述

The first line of the input is a single integer which is the number of test cases. T test cases follow.

Each test case has a single integer , representing the total number of luxury cars in Sumo.

输出描述

For each test case, print a single line containing an integer modulo .

示例1

输入:

2
1
2

输出:

1
4

原站题解

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

Python(2.7.3) 解法, 执行用时: 20ms, 内存消耗: 3044K, 提交时间: 2020-06-06 14:58:29

def fastExpMod(b, e, m):
    result = 1
    while e != 0:
        if (e&1) == 1:
            result = (result * b) % m
        e >>= 1
        b = (b*b) % m
    return result

m = int (input())
while m:
    n = int (input())
    cnt=n*fastExpMod(2,n-1,1000000007)%1000000007
    print(cnt)
    m = m-1;

C++11(clang++ 3.9) 解法, 执行用时: 3ms, 内存消耗: 492K, 提交时间: 2020-06-06 15:48:06

#include<bits/stdc++.h>
using namespace std;
const int MOD=1e9+7;
typedef long long ll;

int t;
ll n;

ll quick(ll a,ll b)
{
	ll res=1;
	while(b) {
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}

int main()
{
	cin>>t;
	while(t--){
		cin>>n;
		cout<<n*quick(2,n-1)%MOD<<endl;
	}
}

C++14(g++5.4) 解法, 执行用时: 4ms, 内存消耗: 580K, 提交时间: 2020-06-06 14:00:37

#include<bits/stdc++.h>
using namespace std;
const int MOD=1e9+7;
int t;
typedef long long ll;
ll n;
ll quick(ll a,ll b)
{
	ll res=1;
	while(b)
	{
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}
int main()
{
	cin>>t;
	while(t--)
	{
		cin>>n;
		cout<<n*quick(2,n-1)%MOD<<endl;
	}
}

Python3(3.9) 解法, 执行用时: 21ms, 内存消耗: 2808K, 提交时间: 2021-03-23 15:26:10

md = 1000000000 + 7
for _ in range(int(input())):
    n = int(input())
    ans = pow(2,n - 1,md)
    ans *= n
    ans %= md
    print(int(ans))

上一题