Created
February 28, 2019 15:11
-
-
Save Abhinay-g/53482c6aadc81080f7d4cd1c34dd6a5b to your computer and use it in GitHub Desktop.
C# code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
class MyClass { | |
static void Main(string[] args) { | |
string[] ip = Console.ReadLine().Trim().Split(' '); | |
long a = Convert.ToInt64(ip[0]); | |
long b = Convert.ToInt64(ip[1]); | |
Console.Write(commDiv(a,b)); | |
} | |
static long gcd(long a, long b) | |
{ | |
if (a == 0) | |
return b; | |
return gcd(b % a, a); | |
} | |
static long commDiv(long a, long b) | |
{ | |
// find gcd of a,b | |
long n; | |
if(a != b){ | |
n = gcd(a, b); | |
} | |
else { | |
n=a; | |
} | |
// Count divisors of n. | |
long result = 0; | |
for (long i = 1; i <= Math.Sqrt(n); i++) | |
{ | |
// if 'i' is factor of n | |
if (n % i == 0) | |
{ | |
// check if divisors are equal | |
if (n / i == i) | |
result += 1; | |
else | |
result += 2; | |
} | |
} | |
return result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment