The 11th Blue Bridge Cup-Conventional Scores

Problem description
If the greatest common divisor of the numerator and denominator of a fraction is 1, the fraction is called a reduced fraction.

For example, 3 4 \frac{3}{4}43 5 2 \frac{5}{2} 25 1 8 \frac{1}{8} 81 7 1 \frac{7}{1} 17 They are all reduced scores.

Excuse me, how many reduced fractions, whose numerator and denominator are both integers between 1 and 2020 (including 1 and 2020)?

Answer submission
This is a result fill-in-the-blank question, you only need to calculate the result and submit it.
The result of this question is an integer. Only fill in this integer when submitting the answer, and fill in the extra content will not be scored.


Answer: 2481215


Problem solution
mathematics:

#include <iostream>
using namespace std;

int gcd(int a, int b)
{
    
    
	return b ? gcd(b, a % b) : a;
}

int main()
{
    
    
	int ans = 0;
	for (int i = 1; i <= 2020; i ++)
		for (int j = 1; j <= 2020; j ++)
			if(gcd(i, j) == 1)
				ans ++;
				
	cout << ans << endl;
	return 0;			
}

Lanqiao Cup C/C++ Group Provincial Competition Past Years Questions

Guess you like

Origin blog.csdn.net/weixin_46239370/article/details/115328128