HBC13890HGCD题解 (每日一词:hh)

素流年 算法基础篇 39 0
想要成为编程高手?那就来试试全网最全C++题库,让您在练习中快速成长。
HH is learning GCD today, GCD is short for Greatest Common Divisor. You can look at this implementation: long long gcd{. } But HH is so careless that he changes "%" into "-", let's call this new funtion HH′s Greatest Common Divisor . You can look at this implementation: long long hgcd {. } Now HH run HGCD(a,b) for all 1≤a≤n, 1≤b≤n,HH wants to know how many times does his algorithm - HGCD works correctly. Note: void swap{

HH is learning GCD today, GCD is short for Greatest Common Divisor.  You can look at this implementation: long long gcd(long long a, long long b){ while(a > 0 && b > 0){     a %= b;     swap(a , b); } return a + b; } But HH is so careless that he changes "%" into "-", let's call this new funtion HH′s Greatest Common Divisor (HGCD). You can look at this implementation: long long hgcd(long long a, long long b) {     while (a > 0 && b > 0) {         a -= b;         swap(a , b);     }     return a + b; } Now HH run HGCD(a,b) for all 1≤a≤n, 1≤b≤n,HH wants to know how many times does his algorithm - HGCD works correctly.  Note: void swap(long long &a, long long &b){     long long t = a;     a = b; b = t; }

HBC13890HGCD题解
(每日一词:hh)-第1张图片-东莞河马信息技术
(图片来源网络,侵删)
不断学习,不断挑战,才能在编程领域中脱颖而出!全网最全C++题库,助您成为编程高手!

标签: HBC13890HGCD题解