Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit bc30a6d

Browse files
authored
Create gcd
1 parent 55feeff commit bc30a6d

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

‎gcd

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const euclideanGCD = (a,b) => {
2+
3+
if(b > a){
4+
a = a ^ b;
5+
b = a ^ b;
6+
a = a ^ b;
7+
}
8+
9+
if(b === 0){
10+
return a;
11+
}
12+
13+
return euclideanGCD(b,a%b);
14+
15+
}
16+
17+
const gcd = (a,b) => {
18+
19+
if(a === 0) return b;
20+
if(b === 0) return a;
21+
22+
for(let i = Math.min(a,b)>>1; i >= 1; i--){
23+
if(a%i === 0 && b%i === 0) return i;
24+
}
25+
26+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /