F Sumo and Luxury Car

题目地址:

https://ac.nowcoder.com/acm/contest/5954/F

基本思路:

根据题意我们由组合数学公式比较容易推出答案为 然后化简一下实际上就是直接快速幂运算就是了。

参考代码:

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
#define IO std::ios::sync_with_stdio(false)
#define int long long
#define rep(i, l, r) for (int i = l; i <= r; i++)
#define per(i, l, r) for (int i = l; i >= r; i--)
#define mset(s, _) memset(s, _, sizeof(s))
#define pb push_back
#define pii pair <int, int>
#define mp(a, b) make_pair(a, b)
#define INF (int)1e18

inline int read() {
  int x = 0, neg = 1; char op = getchar();
  while (!isdigit(op)) { if (op == '-') neg = -1; op = getchar(); }
  while (isdigit(op)) { x = 10 * x + op - '0'; op = getchar(); }
  return neg * x;
}
inline void print(int x) {
  if (x < 0) { putchar('-'); x = -x; }
  if (x >= 10) print(x / 10);
  putchar(x % 10 + '0');
}

int mod = 1e9 + 7;
int qpow(int a,int x) {
  int ret = 1;
  while (x) {
    if (x & 1)
      ret = ret * a % mod;
    a = a * a % mod;
    x >>= 1;
  }
  return ret;
}
signed main() {
  //IO;
  int T;
  T = read();
  while (T--) {
    int n = read();
    int ans = n * qpow(2, n - 1);
    ans %= mod;
    print(ans);
    puts("");
  }
  return 0;
}