public IInteger eulerPhi() throws ArithmeticException { IAST ast = factorInteger(); IInteger phi = IntegerSym.valueOf(1); for (int i = 1; i < ast.size(); i++) { IAST element = (IAST) ast.get(i); IntegerSym q = (IntegerSym) element.get(1); int c = ((IInteger) element.get(2)).toInt(); if (c == 1) { phi = phi.multiply(q.subtract(IntegerSym.valueOf(1))); } else { phi = phi.multiply(q.subtract(IntegerSym.valueOf(1)).multiply(q.pow(c - 1))); } } return phi; }