You are viewing a single comment's thread. Return to all comments →
c#:
static void Main(String[] args) { string[] tokens_n = Console.ReadLine().Split(' '); int n = Convert.ToInt32(tokens_n[0]); int m = Convert.ToInt32(tokens_n[1]); string[] a_temp = Console.ReadLine().Split(' '); int[] a = Array.ConvertAll(a_temp,Int32.Parse); string[] b_temp = Console.ReadLine().Split(' '); int[] b = Array.ConvertAll(b_temp,Int32.Parse); var aLCM = a.Aggregate(LCM); var bGCD = b.Aggregate(GCD); Console.WriteLine( Enumerable.Range(1,bGCD/aLCM) .Where(i=> bGCD % (aLCM*i) == 0).Count()); } static int GCD(int a, int b) { return b == 0 ? a : GCD(b, a % b); } static int LCM(int a, int b) { var k=GCD(a,b); a/=k; return a*b; }
Seems like cookies are disabled on this browser, please enable them to open this website
Between Two Sets
You are viewing a single comment's thread. Return to all comments →
c#: