alexjercan/bugnet huggingface dataset:
Problem p02469 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using namespace std;

// Nayeem Shahriar Joy,Applied Physics And Electronic Engineering,University of
// Rajshahi.

int gcd(int b, int a) {
  if (a < b) {
    swap(a, b);
  }
  int c = 0;
  while (b > 0) {
    c = a % b;
    a = b;
    b = c;
  }
  return a;
}

int main()

{

  int b = 0, c = 0, d = 0, i = 0, j = 0, a1 = 0, b1 = 0, c1 = 0;

  int n, a, pr = 1;

  cin >> n;

  cin >> a;

  for (i = 0; i < n - 1; i++)

  {
    cin >> b;

    a1 = a;

    b1 = b;

    c1 = (a1 * b1) / gcd(a, b);

    a = c1;
  }

  cout << c1 << endl;

  return 0;
}

Error: TLE

Fixed submission:

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

using namespace std;

// Nayeem Shahriar Joy,Applied Physics And Electronic Engineering,University of
// Rajshahi.

int main()

{
  vector<int> p;

  long long int i = 0;

  int n, a;

  cin >> n;

  while (n--)

  {
    cin >> a;
    p.push_back(a);
  }
  int l = p.size();
  sort(p.begin(), p.end());
  for (i = p[l - 1];; i++) {
    int x = 1;
    for (int j = 0; j < l; j++) {
      if (i % p[j] != 0) {
        x = 0;
        break;
      }
    }
    if (x == 1) {
      cout << i << endl;
      return 0;
    }
  }
}
Problem p02469 (C++) — buggy submission, verdict: Runtime Error

#include <iomanip>
#include <iostream>
#include <math.h>
using namespace std;

int main() {
  int n = 0, a = 0, b = 0, c = 0, d = 0, i = 0, j = 0, a1 = 0, b1 = 0, c1 = 0;
  cin >> n;
  cin >> a;
  for (i = 0; i < n - 1; i++) {
    cin >> b;
    a1 = a;
    b1 = b;
    if (a < b) {
      swap(a, b);
    }
    while (b > 0) {
      c = a % b;
      a = b;
      b = c;
    }
    c1 = (a1 * b1) / a;
    a = c1;
  }
  cout << c1 << endl;
}

Error: -8

Fixed submission:

#include <iomanip>
#include <iostream>
#include <math.h>
using namespace std;

int main() {
  int n = 0, a = 0, b = 0, c = 0, d = 0, i = 0, j = 0, a1 = 0, b1 = 0, c1 = 0;
  while (1) {
    cin >> n;
    cin >> a;
    for (i = 0; i < n - 1; i++) {
      cin >> b;
      a1 = a;
      b1 = b;
      if (a < b) {
        swap(a, b);
      }
      while (b > 0) {
        c = a % b;
        a = b;
        b = c;
      }
      c1 = (a1 * b1) / a;
      a = c1;
    }
    cout << c1 << endl;
  }
}
Problem p02469 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int gcd(int a, int b) {
  if (a < b) {
    swap(a, b);
  }
  if (a % b == 0)
    return b;
  return gcd(b, a % b);
}
int main() {
  int i, n, a, b = 1;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &a);
    b = (b * a) / gcd(b, a);
  }
  printf("%d\\n", b);
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int gcd(int a, int b) {
  if (a < b) {
    swap(a, b);
    if (a % b == 0)
      return b;
    return gcd(b, a % b);
  }
}
int main() {
  int i, n, a, b = 1;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &a);
    b = (b * a) / gcd(b, a);
  }
  printf("%d\\n", b);
  return 0;
}
Problem p02469 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n;
  cin >> n;
  int a[n];
  int b[10][1000] = {};
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    int k = a[i];
    for (int m = 2; m <= k;) {
      if (k == 1) {
        break;
      }
      if (k % m == 0) {
        k = k / m;
        b[i][m] += 1;
        continue;
      }
      m++;
    }
  }

  for (int g = 2; g <= 1000; g++) {
    for (int m = 1; m < n; m++) {
      if (b[0][g] < b[m][g]) {
        b[0][g] = b[m][g];
      }
    }
  }

  // for(int i=0;i<1000;i++){
  // if(b[0][i]==0){continue;}
  // cout<<i<<"*"<<b[0][i]<<" ";
  // }

  long long ans = 1;
  for (int h = 0; h < 1000; h++) {
    ans = ans * pow(h, b[0][h]);
  }

  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  int a[n];
  int b[10][1000] = {};
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    int k = a[i];
    for (int m = 2; m <= k;) {
      if (k == 1) {
        break;
      }
      if (k % m == 0) {
        k = k / m;
        b[i][m] += 1;
        continue;
      }
      m++;
    }
  }

  for (int g = 0;; g++) {
    for (int m = 1; m < n; m++) {
      if (b[0][g] < b[m][g]) {
        b[0][g] = b[m][g];
      }
    }
  }

  int ans = 1;
  for (int h = 0; h < n; h++) {
    ans = ans * pow(h, b[0][h]);
  }

  cout << ans << endl;

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

#include <iostream>
#include <vector>
using namespace std;
inline int gcd(int x, int y) {
  if (!y)
    return x;
  return gcd(y, x % y);
}
inline int lcm(int x, int y) { return (x * y) / gcd(y, x % y); }
int main() {
  int n, x;
  vector<int> v;
  cin >> n;
  for (int i = 1; i <= n; ++i)
    cin >> x, v.push_back(x);
  for (int i = 0; i < n - 1; ++i) {
    v[i + 1] = lcm(v[i], v[i + 1]);
  }
  cout << v[n - 1] << endl;
  return 0;
}

Error: -8

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;
inline int gcd(int x, int y) {
  if (!y)
    return x;
  return gcd(y, x % y);
}
inline int lcm(int x, int y) { return (x * y) / gcd(y, x % y); }
int main() {
  int n, x;
  vector<int> v;
  cin >> n;
  for (int i = 1; i <= n; ++i)
    cin >> x, v.push_back(x);
  for (int i = 0; i < n; ++i) {
    v[i + 1] = lcm(v[i], v[i + 1]);
  }
  cout << v[n - 1] << endl;
  return 0;
}
Problem p02469 (C++) — buggy submission, verdict: Runtime Error

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

int gcd(int m, int n) {
  if (n == 0)
    return m;
  return gcd(n, m % n);
}

int lcm(int m, int n) { return m * n / gcd(m, n); }

int main() {
  int n, A[10];

  cin >> n;
  for (int i = 0; i <= n - 1; i++)
    cin >> A[i];
  int ans = A[0];
  for (int i = 1; i <= n - 1; i++)
    ans = lcm(ans, A[i]);
  cout << ans << endl;
  return 0;
}

Error: -11

Fixed submission:

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

int gcd(int m, int n) {
  if (n == 0)
    return m;
  return gcd(n, m % n);
}

int lcm(int m, int n) { return m * n / gcd(m, n); }

int main() {
  int n, A[n - 1];

  cin >> n;
  for (int i = 0; i <= n - 1; i++)
    cin >> A[i];
  int ans = A[0];
  for (int i = 1; i <= n - 1; i++)
    ans = lcm(ans, A[i]);
  cout << ans << endl;
  return 0;
}
Problem p02469 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;

long long int n, a, b, t;

int gcd(int m, int n) {
  while (m != n) {
    if (m > n)
      m = m - n;
    else
      n = n - m;
  }
  return m;
}

int main() {
  cin >> n;
  cin >> a >> b;
  t = a * b / gcd(a, b);
  for (int i = 0; i < n - 2; i++) {
    cin >> a;
    t = t * a / gcd(t, a);
  }
  cout << t << endl;
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;

int n, t, k;
int a[114514810];

int main() {
  for (int i = 0; i < 114514810; i++)
    a[i] = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> t;
    k = t;
    while (k < 114514810) {
      a[k]++;
      k = k + t;
    }
  }
  t = 0;
  while (1) {
    if (a[t] == n) {
      cout << t << endl;
      break;
    }
    t++;
  }
}
Problem p02469 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <queue>
#include <vector>
using namespace std;
const int maxn = 12;
int n;
int a[maxn];

int dd;

long long LCM(int a[], int n) {
  long long m = 1;
  for (int i = 0; i < n; i++)
    m *= a[i];
  long long _min = m, cnt = 0;
  for (int i = 0; i < n; i++) {
    a[i] = m / a[i];
  }
  int pos;
  for (;;) {
    sort(a, a + n);
    //         for(int i=0; i<n; i++) printf("%d ",a[i]);
    //         printf("\\n");
    pos = lower_bound(a, a + n, 1) - a;
    if (a[pos] == 1 || pos == n - 1)
      return m / a[pos];
    for (int i = 0; i < n; i++) {
      if (i != pos)
        a[i] %= a[pos];
    }
  }
  return 0;
}
int main() {
  //    freopen("in.txt","r",stdin);
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  printf("%ld\\n", LCM(a, n));
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <queue>
#include <vector>
using namespace std;
const int maxn = 12;
int n;
int a[maxn];

int dd;

long long LCM(int a[], int n) {
  long long m = 1;
  for (int i = 0; i < n; i++)
    m *= a[i];
  long long _min = m, cnt = 0;
  for (int i = 0; i < n; i++) {
    a[i] = m / a[i];
  }
  int pos;
  for (;;) {
    sort(a, a + n);
    pos = lower_bound(a, a + n, 1) - a;
    if (a[pos] == 1 || pos == n - 1)
      return m / a[pos];
    for (int i = 0; i < n; i++) {
      if (a[i] != a[pos])
        a[i] %= a[pos];
    }
  }
  return 0;
}
int main() {
  //    freopen("in.txt","r",stdin);
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  printf("%ld\\n", LCM(a, n));
  return 0;
}
Problem p02469 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define int long long
#define MOD 1000000007
int gcd(int a, int b) {
  if (a % b == 0)
    return b;
  return gcd(b, a % b);
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
signed main() {
  int n;
  int a[11];
  cin >> n;
  rep(i, n) cin >> a[i];
  int ans = a[0];
  rep(i, n) ans = lcm(ans, a[i]);
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define int long long
#define MOD 1000000007
int gcd(int a, int b) {
  if (a % b == 0)
    return b;
  return gcd(a, b % a);
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
signed main() {
  int n;
  int a[11];
  cin >> n;
  rep(i, n) cin >> a[i];
  int ans = a[0];
  rep(i, n) ans = lcm(ans, a[i]);
  cout << ans << endl;
  return 0;
}
Problem p02470 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <bitset>
#include <fstream>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string.h>
using namespace std;

int main() {
  std::istream &c_in = cin;
  map<int, int> t;
  int n;
  c_in >> n;
  int a = n;
  int i = 2;
  while (a != 1) {
    if ((a % i) == 0) {
      a /= i;
      t[i]++;
      continue;
    }
    i += 1 + (i & 1);
    if (i > ::sqrt(a)) {
      t[a]++;
      break;
    }
  }

  const long N = 1000000000;
  std::bitset<N / 2 + 1> *pflg = new bitset<N / 2 + 1>();
  std::bitset<N / 2 + 1> &flg = *pflg;
  flg.set(0);
  int even = 0;
  bool haseven = t.find(2) != t.end();
  if (haseven) {
    even = (n - 2) / 2;
    t.erase(t.find(2));
  }
  for (map<int, int>::iterator r = t.begin(); r != t.end(); ++r) {
    for (int i = 1; i * r->first < n; i += 2) {
      flg.set((i * r->first - 1) / 2);
    }
  }
  int odds = flg.count();
  if (!haseven) {
    flg.reset();
    for (map<int, int>::iterator r = t.begin(); r != t.end(); ++r) {
      for (int i = 2; i * r->first < n; i += 2) {
        flg.set(i * r->first / 2);
      }
    }
    even = flg.count();
  }
  cout << n - odds - even << endl;
}

Error: MLE

Fixed submission:

#include <bitset>
#include <fstream>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string.h>
using namespace std;

int main() {
  std::istream &c_in = cin;

  map<int, int> t;
  int n;
  c_in >> n;
  int a = n;
  int i = 2;
  while (a != 1) {
    if ((a % i) == 0) {
      a /= i;
      t[i]++;
      continue;
    }
    i += 1 + (i & 1);
    if (i > ::sqrt(a)) {
      t[a]++;
      break;
    }
  }

  const long N = 1000000000;
  std::bitset<N + 1> *pflg = new bitset<N + 1>();
  std::bitset<N + 1> &flg = *pflg;
  flg.set(0);
  for (map<int, int>::iterator r = t.begin(); r != t.end(); ++r) {
    for (int i = 1; i * r->first < n; ++i) {
      // flg.reset(i*r->first);
      flg.set(i * r->first);
    }
  }
  cout << n - flg.count() << endl;
}
Problem p02470 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int n;
int num[11];
int Phi_f(int num) {
  int ans = num;
  for (int i = 2; i * i <= n; ++i) {
    if (num % i == 0) {
      ans -= ans / i;
      while (num % i == 0)
        num /= i;
    }
  }
  if (num > 1)
    ans -= ans / num;
  return ans;
}
int main() {
  cin >> n;
  cout << Phi_f(n) << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
long long n;
int main() {
  cin >> n;
  long long N = n;
  long long pf[1000000] = {0};
  for (int i = 2; 2 * i <= n; ++i) {
    for (;;) {
      if (N % i == 0) {
        N /= i;
        pf[i]++;
      } else {
        break;
      }
    }
  }
  long long ans = n;
  for (int i = 2; 2 * i <= n; ++i) {
    if (pf[i]) {
      ans = (ans / i) * (i - 1);
    }
  }
  if (ans == n)
    ans -= 1;
  cout << ans << endl;
  return 0;
}
Problem p02470 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

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

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

class bunkai {
private:
  int n;
  int s[10000];

public:
  void br(int num) {
    int count = 0;
    if (num % 2 == 0) {
      s[count] = 2;
      count++;
      s[count] = 0;
    }
    for (int i = 3; i <= num;) {
      if (num % i == 0) {
        num = num / i;
        if (s[count - 1] != i) {
          s[count] = i;
          count++;
          s[count] = 0;
        }
        continue;
      }
      i += 2;
    }
  }

  void create(int m) {
    n = m;
    br(m);
  }

  int sr(int S) { return s[S]; }
};

int main() {
  int a, c = 0;
  cin >> a;
  class bunkai b_a;
  b_a.create(a);

  for (int l = 1; l < a; l++) {
    for (int k = 0; b_a.sr(k) != 0; k++) {
      if (l % b_a.sr(k) == 0) {
        break;
      }
      if (b_a.sr(k + 1) == 0) {
        c++;
      }
    }
  }

  cout << c << endl;

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

#include <iostream>

using namespace std;

typedef long long ll;

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

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

ll minfactor(ll n) {
  ll i;

  if (isPrime(n))
    return n;

  for (i = 2; i <= n; i++) {
    if (n % i == 0)
      break;
  }
  return i;
}

/*
 eulerphi
 ????????????????????¶??° n ???????????????????????????????¢??°?????? ??(n)
 ????±??????????
 */
long eulerphi(long n) {
  long phi = n;
  long m;
  long m0 = 0;

  // n ??? 0 ????????°?????´?????????????????????????????????????????? 0
  // ?????????
  if (n < 1)
    return (0);

  // ??(1) = 1 ??¨??????
  if (n == 1)
    return (1);

  do {
    m = minfactor(n);
    n /= m;

    if (m0 != m) {
      phi = phi * (m - 1) / m;
      m0 = m;
    }
  } while (n != 1);

  return (phi);
}

int main() {

  ll n, ans = 0;

  cin >> n;

  ans = eulerphi(n);

  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <cstring>
#include <iostream>
#include <numeric>
#include <queue>
#include <vector>

using namespace std;

/*
 * great common divider
 */
int gcd(int x, int y) {
  int tmp;

  if (y == 0)
    return x;

  if (x < y) {
    tmp = y;
    y = x;
    x = tmp;
  }

  return gcd(y, x % y);
}

int main() {

  int n, ans = 0;

  cin >> n;

  for (int i = 1; i <= n; i++) {
    if (gcd(n, i) == 1) {
      ans++;
    }
  }

  cout << ans << endl;

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

#include <stdio.h>
#include <string.h>

int main(void) {
  long int n, i = 2, ins[1000000], cou = 0, f = 0;
  long long int as;

  scanf("%ld", &n);
  as = n;

  while (i * i <= n) {
    if (n % i == 0) {
      n /= i;
      if (f == 0) {
        ins[cou] = i;
        cou++;
        f = 1;
      }
    } else {
      f = 0;
      i++;
    }
  }
  if (n != 1) {
    f = 0;
    for (i = 0; cou > i; i++) {
      if (ins[i] == n)
        f = 1;
    }
    if (!f) {
      ins[cou] = n;
      cou++;
    }
  }

  for (i = 0; cou > i; i++) {
    as = (as / ins[i]) * (ins[i] - 1);
  }
  printf("%ld\\n", as);
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>

int gcd(int a, int b) {
  while (a % b) {
    int buf = b;
    b = a % b;
    a = buf;
  }
  return b;
}

int main(void) {
  int n, i, cou = 0;

  scanf("%d", &n);

  for (i = 1; n > i; i++) {
    if (gcd(n, i) == 1)
      cou++;
  }
  printf("%d\\n", cou);
  return 0;
}
Problem p02470 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <iostream>
#include <math.h>
#include <vector>
using namespace std;
int main() {
  long n, k, m;
  cin >> n;
  m = n;
  k = ceil(sqrt((double)n));
  vector<char> vA(k + 1, 0);
  vector<long> vP;
  vP.reserve(100);
  for (int i = 2; i <= k; ++i) {
    if (vA[i] == 0) {
      vA[i] = 1;
      for (int j = 2; j * i <= k; ++j)
        vA[i * j] = 2;
      if (0 == n % i)
        vP.push_back(i);
      while (0 == m % i)
        m = m / i;
    }
  }

  if (1 != m)
    vP.push_back(m);

  double c = n;
  for (int i = 0; i < vP.size(); ++i)
    c *= (1.0 - 1.0 / (double)vP[i]);
  int a = int(c + 0.001);
  cout << a << "\\n";
  return 0;
}

Error: MLE

Fixed submission:

#include <iostream>
#include <math.h>
#include <vector>
using namespace std;
int main() {
  long n, k;
  cin >> n;
  k = ceil(sqrt((double)n));
  vector<char> vA(n + 1, 0);
  vector<long> vP;
  vP.reserve(100);
  for (int i = 2; i <= n; ++i) {
    if (vA[i] == 0) {
      vA[i] = 1;
      if (i <= k) {
        for (int j = 2; j * i <= n; ++j)
          vA[i * j] = 2;
      }
      if (0 == n % i)
        vP.push_back(i);
    }
  }
  double c = n;
  for (int i = 0; i < vP.size(); ++i)
    c *= (1.0 - 1.0 / (double)vP[i]);
  int a = int(c + 0.001);
  cout << a << "\\n";
  return 0;
}
Problem p02470 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int Euler_Phi(int n) {
  int res = n;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      res = res / i * (i - 1);
      while (n % i == 0)
        n /= i;
    }
  }
  if (n != 1)
    res = res / n * (n - 1);
  return res;
}

int main() {
  int n;
  cin >> n;
  cout << Euler_Phi(n) << endl;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int min_mul(int n, int m) {
  if (m == 0)
    return n;
  else
    min_mul(m, n % m);
}

int main() {
  int n, count = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    if (min_mul(n, i) == 1)
      count++;
  }
  cout << count << endl;
  return 0;
}
Problem p02470 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>
int n, r;
int main() {
  scanf("%d", &n);
  r = n;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0)
      r = 1LL * r * (i - 1) / i;
    while (n % i == 0)
      n /= i;
  }
  if (n != 1)
    r = 1LL * r * (n - 1) / n;
  printf("%d\\n", r);
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>

int N, C, S;

int main() {
  scanf("%d", &N);

  if (N % 2 == 0) {
    S = 2;
  } else {
    S = 1;
  }

  for (int i = 1; i < N; i += S) {
    if (std::__gcd(N, i) == 1) {
      C++;
    }
  }

  printf("%d\\n", C);

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

#include <iostream>
using namespace std;
int n, sum;
int main() {
  cin >> n;
  sum = n;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      sum = sum / i * (i - 1);
      while (n % i == 0) {
        n /= i;
      }
    }
  }
  if (n != 1) {
    sum = sum / n * (n - 1);
  }
  cout << sum << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
int n, sum, S;
int main() {
  cin >> n;
  S = 1;
  if (n % 2 == 0) {
    S = 2;
  }
  for (int i = 1; i <= n; i += S) {
    if (__gcd(i, n) == 1) {
      sum++;
    }
  }
  cout << sum << endl;
}
Problem p02470 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;

vector<int> v;

void prime(int n) {
  while (n != 1) {
    if (n == 2 || n == 3) {
      v.push_back(n);
      n /= n;
      break;
    }

    for (int i = 2; i <= sqrt(n); i++) {
      if (n % i == 0) {
        n /= i;
        v.push_back(i);
        break;
      }
      if (i == (int)sqrt(n)) {
        v.push_back(n);
        n /= n;
        break;
      }
    }
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  prime(n);
  v.erase(unique(v.begin(), v.end()), v.end());
  int Ans = n;
  for (int i = 0; i < v.size(); i++) {
    Ans = Ans - Ans / v[i];
  }
  cout << Ans << endl;
}

Error: TLE

Fixed submission:

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

bool prime(int m, int n) {
  while (m % n != 0) {
    int temp = m % n;
    m = n;
    n = temp;
  }
  if (n == 1) {
    return true;
  } else
    return false;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  int count = 0;
  for (int i = 1; i < n; i++) {
    if (prime(n, i))
      count++;
  }
  cout << count << endl;
}