What is the fastest way to calculate parity of sum of divisors of a number without computing the sum of divisors of the given number $n$ by the formula stated in these answers formula to calculate sum of divisors on mathematics stackexchange
I also came across this code which calculates the parity of sum of divisors of a number n but couldn't get the logic .
// divsum stores the parity of sum of divisors of number n
int calc(long long n) {
bool divisibleBy2 = n % 2 == 0;
while (n % 2 == 0) n /= 2;
// n odd
int nFactors = int (divisibleBy2);
int divSumParity = 1;
for (int i = 2; (long long) i * i * i <= n; i ++) {
if (n % i == 0) {
int e = 0;
while (n % i == 0) n /= i, e ++;
if (e % 2 == 1) divSumParity = 0;
nFactors ++;
}
}
if (n > 1) {
if (isSquare(n)) {
nFactors += 1;
} else if (isPrime(n)) {
nFactors += 1;
divSumParity = 0;
} else {
nFactors += 2;
divSumParity = 0;
}
}
return 2*(nFactors%2) + divSumParity;
}