As per Payment of Gratuity Act 1972, Wages are defined as all emoluments which are earned by an employee while on duty or on leave in accordance with the terms and conditions of his employment and which are paid or are payable to him in cash and includes dearness allowance but does not include any bonus, commission, house rent allowance, overtime wages and any other allowance. So practically it is determined as sum of basic pay and DA. CTC is wider and includes amounts which are actually not paid to the employee (like cash value of leave employer's contribution to PF, ESI, Gratuity etc) . So, that cannot be used.
As regards calculation of Gratuity, the legal provision is "For every completed year of service or part thereof in excess of six months, the employer shall pay gratuity to an employee at the rate of fifteen days' wages based on the rate of wages last drawn by the employee concerned". Thus it has to be monthly wages divided by 26 and then multiplied by 15. There is no need to bring in 30 in the calculation. The formula shall be P*(Q/26)*15