Blue Bridge Cup 2020 11th C language group B provincial exercise problem solution-exercise B. Conventional score

Daily Questions (Ninety-five)

The 11th Blue Bridge Cup C Language Group B Provincial Competition Exercise B: Conventional score (5')

Insert picture description here
C++ code:

#include<iostream>
using namespace std;
int gcd(int a, int b)
{
    
    
	return b ? gcd(b, a % b) : a;
}

int main()
{
    
    
	int sum = 0;
	//分子分母相同的情况
	sum = 1;
	
	int sum2 = 0;
	//分子小于分母的情况
	for(int i = 1; i < 2020; i++)
	{
    
    
		for(int j = i + 1; j <= 2020; j++)
		{
    
    
			if(gcd(i, j) == 1)
			{
    
    
				sum2++;
			}
		}
	} 
	sum += sum2 * 2;
	cout << sum << endl;
	return 0;
}

Operation result:
Insert picture description here
So the answer is:
2481215

note! Some people will count the same denominator and numerator as different, such as 1/1, 2/2, 3/3, ..., 2020/2020, and think that there are 2020 approximate scores with the result of 1, so the answer and standard The answer is different. Know that since the title says it is a score, then at most consider the possibility that it is 1 once!

If you like my article, please remember three consecutive times, like and follow the collection, every like and every one of your attention and every collection will be my infinite motivation on the way forward! ! ! ↖(▔▽▔)↗Thank you for your support, the next issue will be more exciting! ! !

Guess you like

Origin blog.csdn.net/qq_44631615/article/details/113802835