- #1
Gaussianheart
- 31
- 0
Here is an algorithm very simple to find a common factor to a and b.
An example :
a=867
b=1989
1. We compute a'=a mod 10 and b'=b mod 10 so a'=7 b'=9
2. We solve a'x mod 10 = b' (we can use a table)
x=7 7*a'=49=9 mod 10=b'
3. We compute c=x*a=7*867=6069
4. c>b we compute d=(c-a)/10=(6069-1989)/10=4080/10=408
5. If d is even we divide by 2 (because a and b are odd the divisor ins consequently an odd
number) e=d/2=408/2=204 we continue 204/2=102 102/2=51. e=51
6. We try a/e=867/51=17 and b/e=1989/51=39 so 51 divide a and b
7. We continue with new values a and b : a=17 b=39 by apllying the same algo looping from 1.
I gave an example but we have to apply some rules before starting the use of the algo :
If a is even and b odd (or b odd a even or a and b both even) we have to divide a (or b or and b)
by 2 until we reach a and b both odds.
a=1522 b=538
The values a and b will be a=761 b=269 so then we can start applying the algo above.
Each time we reach step 7 we have try dividing a and b by e.
I'm very aware that there is a need to fix some problems to make it working quickly.
So the core of the algo was presented above.
Thank you for any improvement.
An example :
a=867
b=1989
1. We compute a'=a mod 10 and b'=b mod 10 so a'=7 b'=9
2. We solve a'x mod 10 = b' (we can use a table)
x=7 7*a'=49=9 mod 10=b'
3. We compute c=x*a=7*867=6069
4. c>b we compute d=(c-a)/10=(6069-1989)/10=4080/10=408
5. If d is even we divide by 2 (because a and b are odd the divisor ins consequently an odd
number) e=d/2=408/2=204 we continue 204/2=102 102/2=51. e=51
6. We try a/e=867/51=17 and b/e=1989/51=39 so 51 divide a and b
7. We continue with new values a and b : a=17 b=39 by apllying the same algo looping from 1.
I gave an example but we have to apply some rules before starting the use of the algo :
If a is even and b odd (or b odd a even or a and b both even) we have to divide a (or b or and b)
by 2 until we reach a and b both odds.
a=1522 b=538
The values a and b will be a=761 b=269 so then we can start applying the algo above.
Each time we reach step 7 we have try dividing a and b by e.
I'm very aware that there is a need to fix some problems to make it working quickly.
So the core of the algo was presented above.
Thank you for any improvement.