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

#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
#define pr(...)                                                                \\
  do {                                                                         \\
    _ost << #__VA_ARGS__ << " = ";                                             \\
    ~(_ost, __VA_ARGS__);                                                      \\
  } while (0);
ostream &_ost = cout;
template <class T> ostream &operator,(ostream &ost, const T &value) {
  return ost << value << ",";
}
ostream &operator~(ostream &ost) { return ost << endl; }
template <class T> string tos(const T &var) {
  ostringstream ss;
  ss << var;
  return ss.str();
}
#define ALL(c) (c).begin(), (c).end()
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RALL(c) (c).rbegin(), (c).rend()

typedef vector<int> vi;
typedef long long ll;
typedef unsigned uint;
typedef unsigned long ul;
typedef unsigned long long ull;

const int mod = 1000000007;
const int INF = 1000000;
const double EPS = 1e-10;

int main() {
  int n;
  cin >> n;
  FOR(i, 0, n) {
    bool ppp = true;
    int a, b;
    cin >> a >> b;
    complex<int> p(a, b);
    int np = norm(p);
    FOR(m, 0, np + 1) { // circle <- square
      FOR(n, 0, np + 1) {
        complex<int> i(m, n);
        int ni = norm(i);
        if (ni != 1 && ni != 0 && ni != np && np % ni == 0) {
          ppp = 0;
          break;
        }
      }
      if (!ppp)
        break;
    }
    cout << (ppp ? "P" : "C") << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
#define pr(...)                                                                \\
  do {                                                                         \\
    _ost << #__VA_ARGS__ << " = ";                                             \\
    ~(_ost, __VA_ARGS__);                                                      \\
  } while (0);
ostream &_ost = cout;
template <class T> ostream &operator,(ostream &ost, const T &value) {
  return ost << value << ",";
}
ostream &operator~(ostream &ost) { return ost << endl; }
template <class T> string tos(const T &var) {
  ostringstream ss;
  ss << var;
  return ss.str();
}
#define ALL(c) (c).begin(), (c).end()
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RALL(c) (c).rbegin(), (c).rend()

typedef vector<int> vi;
typedef long long ll;
typedef unsigned uint;
typedef unsigned long ul;
typedef unsigned long long ull;

const int mod = 1000000007;
const int INF = 1000000;
const double EPS = 1e-10;

int main() {
  int n;
  cin >> n;
  FOR(i, 0, n) {
    bool ppp = true;
    int a, b;
    cin >> a >> b;
    complex<int> p(a, b);
    FOR(m, 0, norm(p) + 1) { // circle <- square
      FOR(n, 0, norm(p) + 1) {
        complex<int> i(m, n);
        if (norm(i) != 1 && norm(i) != 0 && norm(i) != norm(p) &&
            norm(p) % norm(i) == 0) {
          ppp = 0;
          break;
        }
      }
      if (!ppp)
        break;
    }
    cout << (ppp ? "P" : "C") << endl;
  }
}