Home > Back-end >  C + + program problem
C + + program problem

Time:03-04

If a score of molecules and the greatest common divisor of the denominator is 1, the score is called both about scores,
3/4, for example, 5/2, 1/8, 7/1 are both about scores,
Excuse me, how many about the score, both molecular and the denominator is an integer between 1 and 2020 (including 1 and 2020)?

CodePudding user response:

There are 2481215, only supplies the reference:
 # include & lt; Stdio. H> 

Int greatest_common_divisor (int a, int b)
{
If (b==0) return a;
The else greatest_common_divisor (b, a % b);
}

Int main (void)
{
Int n1, n2, t, count=0;
For (n1=1; N1 & lt;=2020; N1 + +)
{
For (n=1; N2 & lt;=2020; N2 + +)
{
T=greatest_common_divisor (n1, and n2);
If (t==1)
{
Printf (" % d: \ t: % d \ t the denominator: % d \ n ", + + count, n1, and n2);
}
}
}
return 0;
}
  • Related