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: import java.io.*;
import java.util.*;
public class Main{
    static PrintWriter out;
    static InputReader in;
    public static void main(String args[]){
        out = new PrintWriter(System.out);
        in = new InputReader();
        new Main();
        out.flush(); out.close();
    }
    Main(){
        solve();
    }

	void fft(double[] a, double[] b, boolean invert) {
        int count = a.length;
        for (int i = 1, j = 0; i < count; i++) {
            int bit = count >> 1;
            for (; j >= bit; bit >>= 1) {
                j -= bit;
            }
            j += bit;
            if (i < j) {
                double temp = a[i];
                a[i] = a[j];
                a[j] = temp;
                temp = b[i];
                b[i] = b[j];
                b[j] = temp;
            }
        }
        for (int len = 2; len <= count; len <<= 1) {
            int halfLen = len >> 1;
            double angle = 2 * Math.PI / len;
            if (invert) {
                angle = -angle;
            }
            double wLenA = Math.cos(angle);
            double wLenB = Math.sin(angle);
            for (int i = 0; i < count; i += len) {
                double wA = 1;
                double wB = 0;
                for (int j = 0; j < halfLen; j++) {
                    double uA = a[i + j];
                    double uB = b[i + j];
                    double vA = a[i + j + halfLen] * wA - b[i + j + halfLen] * wB;
                    double vB = a[i + j + halfLen] * wB + b[i + j + halfLen] * wA;
                    a[i + j] = uA + vA;
                    b[i + j] = uB + vB;
                    a[i + j + halfLen] = uA - vA;
                    b[i + j + halfLen] = uB - vB;
                    double nextWA = wA * wLenA - wB * wLenB;
                    wB = wA * wLenB + wB * wLenA;
                    wA = nextWA;
                }
            }
        }
        if (invert) {
            for (int i = 0; i < count; i++) {
                a[i] /= count;
                b[i] /= count;
            }
        }
    }

    long[] multiply(long[] a, long[] b) {
        int resultSize = Integer.highestOneBit(Math.max(a.length, b.length) - 1) << 2;
        resultSize = Math.max(resultSize, 1);
        double[] aReal = new double[resultSize];
        double[] aImaginary = new double[resultSize];
        double[] bReal = new double[resultSize];
        double[] bImaginary = new double[resultSize];
        for (int i = 0; i < a.length; i++) {
            aReal[i] = a[i];
        }
        for (int i = 0; i < b.length; i++) {
            bReal[i] = b[i];
        }
        fft(aReal, aImaginary, false);
        if (a == b) {
            System.arraycopy(aReal, 0, bReal, 0, aReal.length);
            System.arraycopy(aImaginary, 0, bImaginary, 0, aImaginary.length);
        } else {
            fft(bReal, bImaginary, false);
        }
        for (int i = 0; i < resultSize; i++) {
            double real = aReal[i] * bReal[i] - aImaginary[i] * bImaginary[i];
            aImaginary[i] = aImaginary[i] * bReal[i] + bImaginary[i] * aReal[i];
            aReal[i] = real;
        }
        fft(aReal, aImaginary, true);
        long[] result = new long[resultSize];
        for (int i = 0; i < resultSize; i++) {
            result[i] = Math.round(aReal[i]);
        }
        return result;
    }

	long ans = 0;
    void solve(){
    	int n = in.nextInt();
  		long a[] = new long[n];
  		int b[] = new int[n];
  		for(int i = 1; i < n; i++)b[i] = (int)((long)i * i % n);
    	for(int i = 1; i < n; i++)a[b[i]]++;
    	for(int i = 1; i < n; i++){
    		ans += a[2 * b[i] % n];
    	}
    	long result[] = multiply(a, a);
    	for(int i = 0; i < result.length; i++){

    		ans += a[i % n] * result[i];
    	}
    	out.println(ans / 2);
    }

    public static class InputReader{
        BufferedReader br;
        StringTokenizer st;
        InputReader(){
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        public int nextInt(){
            return Integer.parseInt(next());
        }
        public long nextLong(){
            return Long.parseLong(next());
        }
        public double nextDouble(){
            return Double.parseDouble(next());
        }
        public String next(){
            while(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch(IOException e){}
            }
            return st.nextToken();
        }
    }
}, In this Programming Language: Java, Now tell me if this Code is compilable or not?