A-M baby
This commit is contained in:
parent
764da6cbbb
commit
db842d013d
19005 changed files with 197040 additions and 7 deletions
|
|
@ -0,0 +1,9 @@
|
|||
public static long gcd(long a, long b){
|
||||
long factor= Math.max(a, b);
|
||||
for(long loop= factor;loop > 1;loop--){
|
||||
if(a % loop == 0 && b % loop == 0){
|
||||
return loop;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
public static int gcd(int a, int b) //valid for positive integers.
|
||||
{
|
||||
while(b > 0)
|
||||
{
|
||||
int c = a % b;
|
||||
a = b;
|
||||
b = c;
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
public static long gcd(long u, long v){
|
||||
long t, k;
|
||||
|
||||
if (v == 0) return u;
|
||||
|
||||
u = Math.abs(u);
|
||||
v = Math.abs(v);
|
||||
if (u < v){
|
||||
t = u;
|
||||
u = v;
|
||||
v = t;
|
||||
}
|
||||
|
||||
for(k = 1; (u & 1) == 0 && (v & 1) == 0; k <<= 1){
|
||||
u >>= 1; v >>= 1;
|
||||
}
|
||||
|
||||
t = (u & 1) != 0 ? -v : u;
|
||||
while (t != 0){
|
||||
while ((t & 1) == 0) t >>= 1;
|
||||
|
||||
if (t > 0)
|
||||
u = t;
|
||||
else
|
||||
v = -t;
|
||||
|
||||
t = u - v;
|
||||
}
|
||||
return u * k;
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
public static long gcd(long a, long b){
|
||||
if(a == 0) return b;
|
||||
if(b == 0) return a;
|
||||
if(a > b) return gcd(b, a % b);
|
||||
return gcd(a, b % a);
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
import java.math.BigInteger;
|
||||
|
||||
public static long gcd(long a, long b){
|
||||
return BigInteger.valueOf(a).gcd(BigInteger.valueOf(b)).longValue();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue