NC207575. SumoandLuxuryCar
描述
输入描述
The first line of the input is a single integerwhich 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))