#include<algorithm>头文件里的
相当于
int gcd(int a, int b)
{
return b ? gcd(b, a%b) : a;
}
举例
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n = 0;
for(int i = 1; i <= 2020; i++)
if(gcd(i, 2020) == 1)
n++;
cout << n << endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int gcd(int a, int b)
{
return b ? gcd(b, a%b) : a;
}
int main()
{
int n = 0;
for(int i = 1; i <= 2020; i++)
if(gcd(i, 2020) == 1)
n++;
cout << n << endl;
return 0;
}
2个代码的结果是一样的