For this Question: Guddu is obsessed with triplets. So, Bablu gives him the following exercise -

Given N find number of triplets (X, Y, Z) such that:
<li> X <= Y
<li> X<sup>2</sup> + Y<sup>2</sup> ≡ Z<sup>2</sup> (modulo N)
<li> 1 <= X, Y and Z <= N-1

As we know Guddu is not a very smart man, help him solve this problem.The first and the only line of input contains a single integer N.

Constraints:
1 <= N <= 500000Print the answer for Guddu.Sample Input 1
4

Sample Output 1
5

Explanation: required triplets are:
(1, 2, 1)
(1, 2, 3)
(2, 2, 2)
(2, 3, 1)
(2, 3, 3)

Sample Input 2
7

Sample Output 2
18, I have written this Solution Code: #pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc  __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
    return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

template<class T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
 
//////////////
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long  
#define f80 __float128
#define pii pair<int,int>
/////////////

using namespace std;
 
typedef long long int64;
typedef long double ld;
typedef unsigned long long lint;
 
const int inf = (1 << 30) - 1;
const int64 linf = (1ll << 62) - 1;
const ld pi = 4 * atan(1.0);
 
struct cd {
    ld real, imag;
 
    cd(ld real, ld imag) {
        this->real = real;
        this->imag = imag;
    }
 
    cd() {}
};
 
inline cd operator + (const cd &a, const cd &b) {
    return cd(a.real + b.real, a.imag + b.imag);
}
 
inline cd operator - (const cd &a, const cd &b) {
    return cd(a.real - b.real, a.imag - b.imag);
}
 
inline cd operator * (const cd &a, const cd &b) {
    return cd(a.real * b.real - a.imag * b.imag, a.real * b.imag + a.imag * b.real);
}
 
inline cd operator / (const cd &a, const ld &b) {
    return cd(a.real / b, a.imag / b);
}
 
const int N = 2e6;
 
cd p[N];
 
int lg = 0;
 
int reverse(int a) {
    int res = 0;
    for (int i = 0; i < lg; i++) {
        if (a & (1 << i)) {
            res |= (1 << (lg - i - 1));
        }
    }
    return res;
}
 
void fft(cd *a, int n, bool inv) {
    for (int i = 0; i < n; i++) {
        if (i < reverse(i)) {
            swap(a[i], a[reverse(i)]);
        }
    }
    for (int len = 1; len < n; len <<= 1) {
        ld angle = 2 * pi / (len * 2) * (inv ? -1 : 1);
        cd wlen(cos(angle), sin(angle));
        for (int i = 0; i < n; i += 2 * len) {
            cd w(1, 0);
            for (int j = 0; j < len; j++) {
                cd u = a[i + j], v = a[i + j + len] * w;
                a[i + j] = u + v;
                a[i + j + len] = u - v;
                w = w * wlen;
            }
        }
    }
    if (inv) {
        for (int i = 0; i < n; i++) {
            a[i] = a[i] / n;
        }
    }
}
 
signed main() {
	#ifdef ANIKET_GOYAL
		freopen("inputf.in","r",stdin);
		freopen("outputf.in","w",stdout);
	#endif
    int n; cin >> n;
    int size = 1;
    while (size < 2 * n) {
        size *= 2;
        lg++;
    }
    fill_n(p, size, cd(0, 0));
    for (int i = 1; i < n; i++) {
        p[(1ll * i * i) % n].real += 1;
    }
    fft(p, size, false);
    for (int i = 0; i < size; i++) {
        p[i] = p[i] * p[i];
    }
    fft(p, size, true);
    int64 ans = 0;
    for (int i = 1; i < n; i++) {
        ans += (int64) (p[(1ll * i * i) % n].real + 0.5);
        ans += (int64) (p[(1ll * i * i) % n + n].real + 0.5);
    }
    vector<int> used(n, false);
    for (int i = 1; i < n; i++) {
        used[(2ll * i * i) % n]++;
    }
    int64 count = 0;
    for (int i = 1; i < n; i++) {
        count += used[(1ll * i * i) % n];
    }
    cout << (ans - count) / 2 + count << endl;
    return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not?