std::gcd - cppreference.com

文章推薦指數: 80 %
投票人數:10人

std::gcd ... constexpr std::common_type_t gcd( M m, N n ); ... Computes the greatest common divisor of the integers m and n . cppreference.com Createaccount Namespaces Page Discussion Variants Views View Edit History Actions std::gcd Fromcppreference.com template constexprstd::common_type_tgcd(Mm,Nn); (sinceC++17) Computesthegreatestcommondivisoroftheintegersmandn. Contents 1Parameters 2Returnvalue 3Remarks 4Exceptions 5Example 6Seealso [edit]Parameters m,n - integervalues [edit]Returnvalue Ifbothmandnarezero,returnszero.Otherwise,returnsthegreatestcommondivisorof|m|and|n|. [edit]Remarks IfeitherMorNisnotanintegertype,orifeitheris(possiblycv-qualified)bool,theprogramisill-formed. Ifeither|m|or|n|isnotrepresentableasavalueoftypestd::common_type_t,thebehaviorisundefined. [edit]Exceptions Throwsnoexceptions. [edit]Example Runthiscode #include intmain(){ constexprintp{2*2*3}; constexprintq{2*3*3}; static_assert(2*3==std::gcd(p,q)); } [edit]Seealso lcm(C++17) constexprfunctiontemplatereturningtheleastcommonmultipleoftwointegers(functiontemplate)[edit] Retrievedfrom"https://en.cppreference.com/mwiki/index.php?title=cpp/numeric/gcd&oldid=131401" Navigation SupportusRecentchangesFAQOfflineversion Toolbox WhatlinkshereRelatedchangesUploadfileSpecialpagesPrintableversionPermanentlinkPageinformation Inotherlanguages 日本語中文 Thispagewaslastmodifiedon10July2021,at14:04. Thispagehasbeenaccessed155,789times. Privacypolicy Aboutcppreference.com Disclaimers



請為這篇文章評分?