List and GCD solution