Do i need to code a function everytime i wanna get the gcd of two long long variables or there is a easier solution?

# | User | Rating |
---|---|---|

1 | ecnerwala | 3648 |

2 | Benq | 3580 |

3 | orzdevinwang | 3570 |

4 | cnnfls_csy | 3569 |

5 | Geothermal | 3568 |

6 | tourist | 3565 |

7 | maroonrk | 3530 |

8 | Radewoosh | 3520 |

9 | Um_nik | 3481 |

10 | jiangly | 3467 |

# | User | Contrib. |
---|---|---|

1 | maomao90 | 174 |

2 | adamant | 164 |

2 | awoo | 164 |

4 | TheScrasse | 160 |

5 | nor | 159 |

6 | maroonrk | 156 |

7 | SecondThread | 150 |

8 | -is-this-fft- | 149 |

9 | pajenegod | 146 |

10 | BledDest | 144 |

Codeforces (c) Copyright 2010-2024 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Apr/15/2024 07:59:04 (k2).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|

`gcd<int64_t>(x,y)`

Thank you, I've tested here, and this function is only available from c++17 onwards

thank you

Is

`__gcd`

wrong with two long long variables? I always use it and have not seen any problems. A test case would be helpful. Thank youWhy rely on an obscure, non-standard function (that might not work everywhere) when you can just implement the Euclidean algorithm yourself with only three lines of code (not counting braces)? If even that amount of typing bothers you, you can add it to your template.

I know in some cases, it's necessary to have a fast gcd algorithm (I have heard of something like binary gcd before I believe), especially because there is modular arithmetic in the standard euclidian gcd algorithm. This probably isn't an issue for him but it's not impossible that he's searching for a fast version of gcd with long longs?