Euclidean algorithm (for greatest common divisor)

Source: Internet
Author: User
Tags greatest common divisor

1 //greatest common divisor for two numbers2#include <iostream>3 using namespacestd;4 intFintMintN)5 {6     if(n==0)7         returnm;8     Else9         returnF (n,m%n);Ten } One intMain () { A     intb; -     inttemp; -Cin>>a>>b; the     if(a<b) -     { -temp=A; -A=b; +b=temp; -     } +Cout<<f (b) <<Endl; A     return 0; at}

Euclidean algorithm, also known as the common factor method, is used to calculate the maximum of two nonnegative integers. The correctness of the results stems from the greatest common divisor C of a and b and the public approximations of a%b.

Euclidean algorithm (for greatest common divisor)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.