Skip to content

Instantly share code, notes, and snippets.

@nobishino
Last active December 24, 2019 12:24
Show Gist options
  • Save nobishino/4a6a0ccb2234683ab2f0cde6ddb77f94 to your computer and use it in GitHub Desktop.
Save nobishino/4a6a0ccb2234683ab2f0cde6ddb77f94 to your computer and use it in GitHub Desktop.
with recursive euclid(x,y) as (
select 56,12
union all
select y, x%y from euclid
where y != 0
)
select x from euclid
where y = 0;
/*
4 = gcd(56,12)
*/
with recursive euclid(x,y) as (
select 4563132817,31176473253
union all
select y, x%y from euclid
where y != 0
)
select x from euclid
where y = 0;
/* 1 がかえるので互いに素 */
@nobishino
Copy link
Author

一応チェックした

Python 3.7.3 (default, Nov 15 2019, 04:04:52) 
[Clang 11.0.0 (clang-1100.0.33.16)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import math
>>> math.gcd(4563132817,31176473253)
1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment