Movatterモバイル変換


[0]ホーム

URL:


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

Commit0236af6

Browse files
committed
fix getGCD return wrong answer when max(a, b) exceeds magnitude of precision determined by p
1 parent0e7addc commit0236af6

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

‎src/utils/Utils.js‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -390,16 +390,20 @@ class Utils {
390390
// Find the Greatest Common Divisor of two numbers
391391
//
392392
staticgetGCD(a,b,p=7){
393-
letbig=Math.pow(10,p-Math.floor(Math.log10(Math.max(a,b))))
394-
a=Math.round(Math.abs(a)*big)
395-
b=Math.round(Math.abs(b)*big)
393+
letfactor=Math.pow(10,p-Math.floor(Math.log10(Math.max(a,b))))
394+
if(factor>1){
395+
a=Math.round(Math.abs(a)*factor)
396+
b=Math.round(Math.abs(b)*factor)
397+
}else{
398+
factor=1
399+
}
396400

397401
while(b){
398402
lett=b
399403
b=a%b
400404
a=t
401405
}
402-
returna/big
406+
returna/factor
403407
}
404408

405409
staticgetPrimeFactors(n){

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp