alexjercan/bugnet huggingface dataset:
Problem p02467 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) REP(i, 0, n)
#define REP(i, s, e) for (int i = (s); i < (int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for (int i = (int)(s - 1); i >= (int)(e); i--)
#define pb push_back
#define all(r) r.begin(), r.end()
#define rall(r) r.rbegin(), r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

using Facts = map<ll, int>;
void factrize(ll n, Facts &mp) {
  if (n < 2)
    return;
  ll m = sqrt(n);
  REP(i, 2, m + 1) {
    int cnt = 0;
    while (n % i == 0) {
      n /= i;
      ++cnt;
    }
    mp[i] += cnt;
  }
  if (n != 1)
    mp[n]++;
}

int main() {
  ll n;
  cin >> n;
  Facts f;
  factrize(n, f);
  cout << n << ":";
  for (auto &p : f) {
    rep(i, p.se) cout << " " << p.fi;
  }
  cout << endl;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define pb(n) push_back(n)
#define mp(n, m) make_pair(n, m)
#define fi first
#define se second
#define all(r) (r).begin(), (r).end()

#define REP(i, s, e) for (int i = (s); i < (e); i++)
#define rep(i, n) REP(i, 0, n)
#define REPE(i, s, e) for (int i = s; i > e; i--)
#define repe(i, n) REPE(i, n, -1)

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef vector<vi> vvi;

const int IMAX = ((1 << 30) - 1) * 2 + 1;
const int INF = 100000000;
const double EPS = 1e-10;
// int mod=1000000007

const int MAX_PRIME = 10000000;

vector<int> is_prime(MAX_PRIME, 1);

void calcPrime() {
  is_prime[0] = is_prime[1] = 0;
  for (int i = 2; i < MAX_PRIME; i++) {
    if (is_prime[i] == 1) {
      for (int j = i * 2; j < MAX_PRIME; j += i) {
        is_prime[j] = 0;
      }
    }
  }
}

int main() {
  int n;
  cin >> n;
  cout << n << ":";
  calcPrime();
  int i = 2;
  while (n > 1) {
    if (is_prime[i] && n % i == 0) {
      n /= i;
      cout << " " << i;
    } else
      i++;
  }
  cout << endl;
}
Problem p02467 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>

// #define rep(i,0,n) for(int i=0; i<n; i++)

using namespace std;

bool fact(int n) {
  int k = sqrt(n);
  if (n % 2 == 0)
    return false;
  else {
    for (int i = 3; i <= k; i = i + 2) {
      if (n % i == 0)
        return false;
    }
    return true;
  }
  return 0;
}

void factorize(int n) {
  vector<int> fac;
  cout << n << ": ";
  if (fact(n) == true) {
    cout << n << endl;
    return;
  }
  while (n % 2 == 0) {
    n /= 2;
    fac.push_back(2);
  }

  if (n != 1) {
    /*
    //int k = sqrt(n);
    for(int i=3; i<=n/2; i = i+2){
            if(n % i == 0){
                    n /= i;
                    //cout << i << " ";
                    fac.push_back(i);
                    i -= 2;
            }
    }*/
    int i = 3;
    while (n > 1) {
      if (n % i == 0) {
        n /= i;
        fac.push_back(i);
      } else {
        i = i + 2;
      }
    }
  }

  // cout << endl;
  int m = fac.size();
  for (int i = 0; i < m - 1; i++) {
    cout << fac[i] << " ";
  }
  cout << fac[m - 1] << endl;
}
int main() {
  int n;
  cin >> n;
  factorize(n);
  // cout << fact(n) << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>

// #define rep(i,0,n) for(int i=0; i<n; i++)

using namespace std;

void factorize(int n) {
  vector<int> fac;
  cout << n << ": ";

  while (n % 2 == 0) {
    n /= 2;
    fac.push_back(2);
  }

  if (n != 1) {
    // int k = sqrt(n);
    /*for(int i=3; i<=n/2; i = i+2){
            if(n % i == 0){
                    n /= i;
                    //cout << i << " ";
                    fac.push_back(i);
                    i -= 2;
            }
    }*/
    int i = 3;
    while (n > 1) {
      if (n % i == 0) {
        n /= i;
        fac.push_back(i);
      } else {
        i = i + 2;
      }
    }
  }

  // cout << endl;
  int m = fac.size();
  if (m == 0)
    cout << n << endl;
  else {
    for (int i = 0; i < m - 1; i++) {
      cout << fac[i] << " ";
    }
    cout << fac[m - 1] << endl;
  }
}

int main() {
  int n;
  cin >> n;
  factorize(n);
  return 0;
}
Problem p02467 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
#define YAKU_MAX 31623

int n, arr[YAKU_MAX], sosu[YAKU_MAX], nn, sosu_ko;

void Eratosthenes() {
  for (int i = 0; i < nn; i++) {
    arr[i] = 1;
  }
  for (int i = 2; i < sqrt(nn); i++) {
    if (arr[i]) {
      for (int j = 0; i * (j + 2) < nn; j++) {
        arr[i * (j + 2)] = 0;
      }
    }
  }

  for (int i = 2; i < nn; i++) {
    if (arr[i]) {
      sosu[sosu_ko] = i;
      sosu_ko++;
    }
  }
}

int main() {
  scanf("%d", &n);
  printf("%d:", n);
  nn = sqrt(n) + 1;
  Eratosthenes();

  while (1) {
    bool comp = false;
    for (int i = 0; sosu_ko > i; i++) {
      if (n == sosu[i]) {
        printf(" %d\\n", sosu[i]);
        return 0;
      }

      else if (!(n % sosu[i])) {
        printf(" %d", sosu[i]);
        n /= sosu[i];
        comp = true;
        break;
      }
    }
    if (!comp) {
      printf(" %d\\n", n);
      return 0;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
#define YAKU_MAX 31623

int n, arr[YAKU_MAX], sosu[YAKU_MAX], nn, sosu_ko;

void Eratosthenes() {
  for (int i = 0; i < nn; i++) {
    arr[i] = 1;
  }
  for (int i = 2; i < sqrt(nn); i++) {
    if (arr[i]) {
      for (int j = 0; i * (j + 2) < nn; j++) {
        arr[i * (j + 2)] = 0;
      }
    }
  }

  for (int i = 2; i < nn; i++) {
    if (arr[i]) {
      sosu[sosu_ko] = i;
      sosu_ko++;
    }
  }
}

int main() {
  scanf("%d", &n);
  printf("%d:", n);
  nn = sqrt(n) + 1;
  Eratosthenes();
  while (1) {
    for (int i = 0; sosu_ko >= i; i++) {
      if (n == sosu[i]) {
        printf(" %d\\n", sosu[i]);
        return 0;
      }

      else if (!(n % sosu[i])) {
        printf(" %d", sosu[i]);
        n /= sosu[i];
        break;
      }
    }
  }
  return 0;
}
Problem p02467 (C++) — buggy submission, verdict: Runtime Error

#include <cmath>
#include <cstdio>
// factorize
using namespace std;
int k = 0;
int A[100000] = {};
//?????????2??????root x ?????§????´???°??????????????±?????\\?????????
int is_prime(int x) {
  // x????´???°??????????????????????????????
  if (x < 2)
    return 0;
  if (x == 2)
    return 1;
  if (x % 2 == 0)
    return 0;
  for (int i = 3; i * i <= x; i++) {
    if (x % i == 0)
      return 0;
  }
  return 1;
}

void prime_in(int x) {
  for (int i = 2; i * i <= x; i++) {
    if (is_prime(i)) {
      A[k] = i;
      k++;
    }
  }
}

int main() {
  int n;
  scanf("%d", &n);
  prime_in(n); // root 12?????§?????±????´???°?????????????????????
  printf("%d:", n);
  int i = 0;

  while (n != 1) {
    if (is_prime(n)) {
      printf(" %d", n);
      break;
    }
    if (n % A[i] == 0) {
      printf(" %d", A[i]);
      n /= A[i];
    } else
      i++;
  }
  printf("\\n");

  return 0;
}

Error: 0

Fixed submission:

#include <cmath>
#include <cstdio>
// factorize
using namespace std;
int k = 0;
int A[100000] = {};
//?????????2??????root x ?????§????´???°??????????????±?????\\?????????
int is_prime(int x) {
  // x????´???°??????????????????????????????
  if (x < 2)
    return 0;
  if (x == 2)
    return 1;
  if (x % 2 == 0)
    return 0;
  for (int i = 3; i * i <= x; i++) {
    if (x % i == 0)
      return 0;
  }
  return 1;
}

void prime_in(int x) {
  for (int i = 2; i * i <= x; i++) {
    if (is_prime(i)) {
      A[k] = i;
      k++;
    }
  }
}

int main() {
  int n;
  scanf("%d", &n);
  prime_in(n); // root 12?????§?????±????´???°?????????????????????
  printf("%d:", n);
  int i = 0; //?´???°??±????????£???????????????num
  //???????????¬???????´???°?????¨..
  if (is_prime(n)) {
    printf(" %d\\n", n);
    return 0;
  } else {
    while (n != 1) {
      if (n % A[i] == 0) {
        printf(" %d", A[i]);
        n /= A[i];
      } else
        i++;
    }
    printf("\\n");
  }

  return 0;
}
Problem p02467 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n = 0;
  int limit;
  scanf("%d", &n);
  printf("%d:", n);
  limit = sqrt(n);
  for (int i = 2; i <= n;) {
    if (n % i == 0) {
      printf(" %d", i);
      n /= i;
    } else
      i++;

    if (i > limit) {
      printf(" %d", n);
      break;
    }
  }
  putchar('\\n');

  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  int n = 0;
  int limit;
  scanf("%d", &n);
  printf("%d:", n);
  limit = sqrt(n);
  for (int i = 2; i <= n || i <= limit;) {
    if (n % i == 0) {
      printf(" %d", i);
      n /= i;
    } else
      i++;
  }
  putchar('\\n');

  return 0;
}
Problem p02467 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <iostream>
using namespace std;

int isPrime(int num) {
  if (num == 2)
    return 1;
  if (num == 3)
    return 1;
  if (num == 4)
    return 0;
  if (num == 5)
    return 1;

  for (int i = 2; i * i <= num; i++) {
    if (num % i == 0) {
      return 0;
    }
  }
  return 1;
}

int main() {

  int input, div = 2;

  cin >> input;

  printf("%d:", input);

  if (isPrime(input)) {
    printf(" %d\\n", input);
    return 0;
  }

  while (input != div) {
    if (input % div == 0) {
      input /= div;
      printf(" %d", div);
    } else {
      div++;
    }
  }
  printf(" %d\\n", div);

  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>
using namespace std;

int main() {

  int input, div = 2;

  cin >> input;

  printf("%d:", input);

  while (input != div) {
    if (input % div == 0) {
      input /= div;
      printf(" %d", div);
    } else {
      div++;
    }
  }
  printf(" %d\\n", div);

  return 0;
}
Problem p02467 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n;
  cin >> n;
  cout << n << ":";
  for (int i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      cout << " " << i;
      n /= i;
    }
  }
  if (n != 1)
    cout << " " << n;
  cout << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  cout << n << ":";

  for (int i = 2; i <= n; i++) {
    while (n % i == 0) {
      cout << " " << i;
      n /= i;
    }
  }
  cout << endl;
}
Problem p02467 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

int main() {
  long long n, m;
  cin >> n;
  m = sqrt(n);
  cout << n << ":";
  for (int i = 2; i <= n; i++) {
    while (n % i == 0) {
      cout << " " << i;
      n /= i;
    }
    if (n == 1)
      break;
    if (i >= sqrt(n)) {
      cout << " " << n;
      break;
    }
  }
  cout << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {
  long long n;
  cin >> n;
  cout << n << ":";
  for (int i = 2; i <= n; i++)
    while (n % i == 0) {
      cout << " " << i;
      n /= i;
    }
  cout << endl;
}
Problem p02467 (C++) — buggy submission, verdict: Time Limit Exceeded

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

bool judge(int s) {
  for (int i = 2; i * i <= s; i++) {
    if (s % i != 0 && (i + 1) * (i + 1) > s) {
      return true;
    }
    if (s % i == 0) {
      return false;
      break;
    }
  }
}

int main() {

  int n, l;
  cin >> n;
  l = n;
  int b[1000] = {};

  if (judge(n)) {
    cout << l << ": " << n << endl;
  }

  else {
    int count = 0;
    for (int m = 2; m <= n;) {
      if (n == 1) {
        break;
      }
      if (n % m == 0 && judge(m)) {
        n = n / m;
        b[count] = m;
        count++;
        continue;
      }
      m++;
    }

    cout << l << ":";
    for (int i = 0;; i++) {
      if (b[i] == 0) {
        cout << endl;
        break;
      }
      cout << " " << b[i];
    }
  }

  return 0;
}


Error: TLE

Fixed submission:

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

bool judge(int s) {
  for (int i = 2; i * i <= s; i++) {
    if (s % i != 0 && (i + 1) * (i + 1) > s) {
      return "truth";
    }
    if (s % i == 0) {
      return "false";
      break;
    }
  }
}

int main() {

  int n, l;
  cin >> n;
  l = n;
  int b[1000] = {};

  int count = 0;
  for (int m = 2; m <= n;) {
    if (n == 1) {
      break;
    }
    if (n % m == 0 && judge(m)) {
      n = n / m;
      b[count] = m;
      count++;
      continue;
    }
    m++;
  }

  cout << l << ":";
  for (int i = 0;; i++) {
    if (b[i] == 0) {
      cout << endl;
      break;
    }
    cout << " " << b[i];
  }

  return 0;
}
Problem p02467 (C++) — buggy submission, verdict: Runtime Error

#include <cmath>
#include <iostream>
using namespace std;
#define N 31623 // √10^9
int main() {
  int n;
  cin >> n;
  int x = n; // n /= i
  cout << n << ":";
  for (int i = 2; i * i <= x; i++) {
    while (n % i == 0) {
      cout << " " << i;
      n /= i;
    }
  }
  if (n != 1) { // 999993031 : 999993031
    cout << " " << n;
  }
  cout << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <cmath>
#include <iostream>
using namespace std;
#define N 31623 // √10^9
int main() {
  int table[N];
  table[0] = table[1] = 0; // not prime number
  for (int i = 2; i <= N; i++) {
    table[i] = 1;
  }
  for (int i = 2; i <= (int)sqrt(N); i++) {
    if (table[i] == 1) { // 倍数は素数でない
      for (int k = i * 2; k <= N; k++) {
        table[k] = 0;
      }
    }
  }
  int n;
  cin >> n;
  int cnt = 0;
  cout << n << ":";
  for (int i = 2; i <= N && n >= 2; ++i) {
    while (table[i] == 1 && n % i == 0) {
      cout << " " << i;
      n /= i;
      cnt++;
    }
  }
  if (cnt == 0) {
    cout << " " << n;
  }
  cout << endl;
  return 0;
}
Problem p02467 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>

using namespace std;

int main() {
  int a;
  cin >> a;

  cout << a << ":";

  vector<int> r;
  int j = 2;
  while (true) {
    if (a == 1) {
      break;
    }
    if (a % j == 0) {
      r.push_back(j);
      a /= j;
    } else {
      j += 1;
    }
    if (j * j > a) {
      r.push_back(a);
      break;
    }
  }
  for (int i : r) {
    cout << ' ' << i;
  }
  cout << endl;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

int main() {
  int a;
  cin >> a;

  cout << a << ":";

  vector<int> r;
  int j = 2;
  while (true) {
    if (a == 1) {
      break;
    }
    if (a % j == 0) {
      r.push_back(j);
      a /= j;
    } else {
      j += 1;
    }
  }
  for (int i : r) {
    cout << ' ' << i;
  }
  cout << endl;
}
Problem p02467 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;

int main() {
  int a;
  scanf("%d", &a);
  printf("%d:", a);
  for (int b = 2; b <= sqrt(a); b++) {
    while (1) {
      if (a % b)
        break;
      a /= b;
      printf(" %d", b);
    }
  }
  if (a != 1)
    printf(" %d", a);
  printf("\\n");
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;

int main() {
  int a;
  scanf("%d", &a);
  printf("%d:", a);
  string s = "";
  while (1) {
    if (a % 2)
      break;
    a /= 2;
    s += " 2";
  }
  for (int b = 3; b <= a; b += 2) {
    while (1) {
      if (a % b)
        break;
      a /= b;
      s += " ";
      s += to_string(b);
    }
  }
  cout << s << endl;
}
Problem p02467 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int n;

int main() {
  cin >> n;
  int def_half_n = n / 2 + 2;
  int def_n = n;
  cout << n << ":";
  while (n % 2 == 0) {
    cout << " " << 2;
    n /= 2;
  }
  if (n == 1) {
    cout << endl;
    return 0;
  }
  for (int i = 3; i < def_half_n; i += 2) {
    while (n % i == 0) {
      cout << " " << i;
      n /= i;
    }
    if (n == 1)
      break;
  }
  if (n == def_n)
    cout << " " << n;
  cout << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int n;

int main() {
  cin >> n;
  int def_n = n;
  cout << n << ":";
  for (int i = 2; i < def_n + 1; i++) {
    while (n % i == 0) {
      cout << " " << i;
      n /= i;
    }
    if (n == 1)
      break;
  }
  cout << endl;
  return 0;
}
Problem p02468 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); i++)
typedef unsigned long long int lint;
const lint C = 1000000007;

lint POW(lint M, lint N) {
  lint ret;
  if (N == 0)
    return 1;
  else {
    ret = POW(M, N / 2);
    if (N % 2 == 0)
      ret = (ret * ret) % C;
    else
      ret = (((ret * ret) % C) * M) % C;
  }
  return ret;
}

int main() {
  lint n, m;
  cin >> m >> n;
  lint t = 1;
  cout << POW(m, n) << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); i++)
typedef unsigned long long int lint;
const lint C = 1000000007;
int main() {
  lint n, m;
  cin >> m >> n;
  lint t = 1;
  REP(i, n) {
    t *= m;
    t = t % C;
  }
  cout << t % C << endl;
  return 0;
}
Problem p02468 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

int main() {
  int64_t m, n, q = 1000000007;
  std::cin >> m >> n;

  int64_t r = 1;
  int64_t m2 = m * m;
  int64_t m4 = m * m * m * m;
  int64_t i = 0;
  for (int64_t j = 0; j < n / 4; j++) {
    r = (r * m4) % q;
    i += 4;
  }
  for (; i < n; i++) {
    r = (r * m) % q;
  }
  std::cout << r << "\\n";
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>

int main() {
  int64_t m, n, q = 1000000007;
  std::cin >> m >> n;

  int64_t r = m % q;
  for (int64_t i = 1; i < n; i++) {
    r = (r * m) % q;
  }
  std::cout << r << "\\n";
  return 0;
}
Problem p02468 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
long long m, n;
#define mod 1000000007

long long pow_mod(long long a, long long b) {
  if (b == 0)
    return 1;
  if (b % 2 == 0) {
    long long d = pow_mod(a, b / 2);
    return ((d % mod) * (d % mod)) % mod;
  }
  return ((a % mod) * (pow_mod(a, (b - 1)) % mod)) % mod;
}
int main() {
  cin >> m >> n;
  cout << pow_mod(m, n) << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
long long m, n;
#define mod 1000000007
int main() {
  cin >> m >> n;
  long long ans = 1;
  for (long long i = 1; i <= n; ++i) {
    ans = (ans *= m) % mod;
  }
  cout << ans << endl;
  return 0;
}
Problem p02468 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cctype>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  long long int m, n;
  cin >> m >> n;
  long long int kk = m * m;
  long long int kkk = m * m * m;
  long long int kkkk = m * m * m * m;
  long long int ans = 1;
  while (n > 4) {
    ans = ((ans * kkkk) % 1000000007);
    n -= 4;
  }
  if (n == 4)
    ans = ((ans * kkkk) % 1000000007);
  else if (n == 3)
    ans = ((ans * kkk) % 1000000007);
  else if (n == 2)
    ans = ((ans * kk) % 1000000007);
  else
    ans = ((ans * m) % 1000000007);
  cout << ans << endl;
  // while(1);
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cctype>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  long long int m, n;
  long long int ans = 1;
  cin >> m >> n;
  while (n--) {
    ans = ((ans * m) % 1000000007);
  }
  cout << ans << endl;
  // while(1);
  return 0;
}
Problem p02468 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
#define king 1000000007

int main() {
  long long m, n, sum = 1;
  cin >> m >> n;
  while (n != 1) {
    if (n % 2 == 1) {
      sum = sum * m % king;
    }
    m = m * m % king;
    n /= 2;
  }
  m = m * sum % king;
  cout << m << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  long long sum, k, m, n;
  cin >> m >> n;
  sum = m;
  k = 1;
  while (k < n) {
    while (sum < 1000000007) {
      sum *= m;
      k++;
      if (k >= n)
        break;
    }
    sum %= 1000000007;
  }
  cout << sum << endl;
  return 0;
}
Problem p02468 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
#define P 1000000007
int main() {
  unsigned long long a, b, s, l = 1;
  cin >> b >> a;
  s = b;
  while (a != 1) {
    if (a % 2) {
      l = l * s % P;
    }
    s = s * s % P;
    a /= 2;
  }
  s = l * s % P;
  cout << s << endl;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
#define P 1000000007
int main() {
  unsigned long long a, b, s;
  cin >> b >> a;
  s = b;
  while (a != 1) {
    s *= b;
    s = s % P;
    a--;
  }
  s = s % P;
  cout << s << endl;
}
Problem p02468 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#define int long long
using namespace std;
signed main() {
  int m, n, mod = 1000000007;
  cin >> m >> n;
  int k = 1;
  while (n) {
    if (n % 2 == 1) {
      k *= m;
      n--;
    }
    m *= m;
    n /= 2;
    k %= mod;
    m %= mod;
  }
  cout << k << endl;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  long m, n;
  cin >> m >> n;
  for (int i = 0; n % 2 == 0; i++) {
    m *= m;
    n /= 2;
  }
  for (int i = 0; m % 3 == 0; i++) {
    m *= m * m;
    n /= 3;
  }
  int d = 1;
  for (int i = 0; i < m; i++) {
    d *= m;
  }
  cout << d % 1000000007 << endl;
}
Problem p02468 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
ll ppp(ll x, ll k) {
  ll res = 1;
  if (k == 0)
    return 1;
  res = ppp(x * x % mod, k / 2);
  if (k & 1)
    res = res * x % mod;
  return res;
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  cout << ppp(n, m) << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <stdio.h>
#define M 1000000007
using namespace std;
typedef long long LL;
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  LL t = n;
  for (int i = 1; i < m; i++) {
    t = (t * n) % M;
  }
  printf("%lld\\n", t);
  return 0;
}
Problem p02468 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <iostream>
using namespace std;
typedef long long ll;

ll pow(ll m, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) {
      res = res * m % mod;
    }
    m = m * m % mod;
    n >>= 1;
  }
  return res;
}
int main() {
  ll a, b;
  cin >> a >> b;
  cout << pow(a, b, 1000000007) << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>
#define X 1000000007
using namespace std;
int main() {
  long long i, m, n, r = 1;

  cin >> m >> n;
  for (i = 0; i < n; i++) {
    r *= m;
    while (r > X) {
      r -= X;
    }
  }
  cout << r << endl;
  return 0;
}