Problem p02468 (C++) — buggy submission, verdict: Time Limit Exceeded

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

//?????????
#pragma region MACRO
#define putans(x) cout << (x) << endl
#define dputans(x)                                                             \\
  std::cerr << "answer: ";                                                     \\
  cout << setprecision(10) << (double)(x) << endl
#define REP(i, a, n) for (int i = (a); i < (int)(n); i++)
#define RREP(i, a, n) for (int i = (int)(n - 1); i >= a; i--)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) RREP(i, 0, n)
#define all(a) begin((a)), end((a))
#define mp make_pair
#define exist(container, n) ((container).find((n)) != (container).end())
#define substr(s, i, l) string((s), (i), (l))
#define tos(x) (to_string((x)))
#ifdef _DEBUG //???????????????????????????????????????????????????
std::ifstream ifs("data.txt");
#define p ifs >>
#else //?????£????????????????????§?????????????????????
#define p cin >>
#endif
#pragma endregion

//???????????°??????????????´
#pragma region CODING_SUPPORT
#define dbg(var0)                                                              \\
  { std::cerr << (#var0) << "=" << (var0) << endl; }
#define dbg2(var0, var1)                                                       \\
  {                                                                            \\
    std::cerr << (#var0) << "=" << (var0) << ", ";                             \\
    dbg(var1);                                                                 \\
  }
#define dbg3(var0, var1, var2)                                                 \\
  {                                                                            \\
    std::cerr << (#var0) << "=" << (var0) << ", ";                             \\
    dbg2(var1, var2);                                                          \\
  }
#define dbgArray(a, n)                                                         \\
  {                                                                            \\
    std::cerr << (#a) << "=";                                                  \\
    rep(i, n) { std::cerr << (a[i]) << ","; }                                  \\
    cerr << endl;                                                              \\
  }
#ifndef _DEBUG
#define dbg1                                                                   \\
  {}
#define dbg2                                                                   \\
  {}
#define dbg3                                                                   \\
  {}
#define dbgArray                                                               \\
  {}
#endif
#pragma endregion
// typedef????????????????????????????¶????????????§?????????
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
typedef pair<int, string> pis;
typedef vector<string> vs;
typedef vector<int> vi;
#pragma endregion
//??????????????°(???????????????????????§??????)
#pragma region CONST_VAL
#define PI (2 * acos(0.0))
#define EPS (1e-9)
#define MOD (ll)(1e9 + 7)
#define INF (ll)(1e9)
#pragma endregion

ll power(ll m, ll n, ll mod = MOD) {
  ll ans = 1;
  ll mbin = m;
  for (ll i = 1; i <= n; i *= 2) {
    if ((n & i) != 0) {
      ans *= mbin;
      ans %= mod;
    }
    mbin = (mbin * mbin) % mod;
  }
  return ans;
}

int main() {
  int m, n;
  p m >> n;
  ll k = power(m, n);
  putans(k);
  return 0;
}

/*
#define i(x) int x; scanf("%d",&x);
#define l(x) ll x; scanf("%lld",&x);
#define d(x) double  x; scanf("%lf",&x);
*/
//??????????£?????????°???
// https://www23.atwiki.jp/akitaicpc/pages/65.html

Error: TLE

Fixed submission:


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

//?????????
#pragma region MACRO
#define putans(x)                                                              \\
  std::cerr << "answer: ";                                                     \\
  cout << (x) << endl
#define dputans(x)                                                             \\
  std::cerr << "answer: ";                                                     \\
  cout << setprecision(10) << (double)(x) << endl
#define REP(i, a, n) for (int i = (a); i < (int)(n); i++)
#define RREP(i, a, n) for (int i = (int)(n - 1); i >= a; i--)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) RREP(i, 0, n)
#define all(a) begin((a)), end((a))
#define mp make_pair
#define exist(container, n) ((container).find((n)) != (container).end())
#define substr(s, i, l) string((s), (i), (l))
#define tos(x) (to_string((x)))
#ifdef _DEBUG //???????????????????????????????????????????????????
std::ifstream ifs("data.txt");
#define p ifs >>
#else //?????£????????????????????§?????????????????????
#define p cin >>
#endif
#pragma endregion

//???????????°??????????????´
#pragma region CODING_SUPPORT
#define dbg(var0)                                                              \\
  { std::cerr << (#var0) << "=" << (var0) << endl; }
#define dbg2(var0, var1)                                                       \\
  {                                                                            \\
    std::cerr << (#var0) << "=" << (var0) << ", ";                             \\
    dbg(var1);                                                                 \\
  }
#define dbg3(var0, var1, var2)                                                 \\
  {                                                                            \\
    std::cerr << (#var0) << "=" << (var0) << ", ";                             \\
    dbg2(var1, var2);                                                          \\
  }
#define dbgArray(a, n)                                                         \\
  {                                                                            \\
    std::cerr << (#a) << "=";                                                  \\
    rep(i, n) { std::cerr << (a[i]) << ","; }                                  \\
    cerr << endl;                                                              \\
  }
#ifndef _DEBUG
#define dbg1                                                                   \\
  {}
#define dbg2                                                                   \\
  {}
#define dbg3                                                                   \\
  {}
#define dbgArray                                                               \\
  {}
#endif
#pragma endregion
// typedef????????????????????????????¶????????????§?????????
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
typedef pair<int, string> pis;
typedef vector<string> vs;
typedef vector<int> vi;
#pragma endregion
//??????????????°(???????????????????????§??????)
#pragma region CONST_VAL
#define PI (2 * acos(0.0))
#define EPS (1e-9)
#define MOD (ll)(1e9 + 7)
#define INF (ll)(1e9)
#pragma endregion

ll power(ll m, ll n, ll mod = MOD) {
  ll ans = 0;
  ll mbin = m;
  for (int i = 1; i <= n; i *= 2) {
    if ((n & i) != 0) {
      ans += mbin;
      ans %= mod;
    }
    mbin = (mbin * mbin) % mod;
  }
  return ans;
}

int main() {
  int m, n;
  p m >> n;
  int k = power(m, n);
  putans(k);
  return 0;
}

/*
#define i(x) int x; scanf("%d",&x);
#define l(x) ll x; scanf("%lld",&x);
#define d(x) double  x; scanf("%lf",&x);
*/
//??????????£?????????°???
// https://www23.atwiki.jp/akitaicpc/pages/65.html