function for T. M. Soundararajan in Maduri.Part 7.Thanks to M K Alagiri