当前位置:网站首页>C language - Blue Bridge Cup - promised score
C language - Blue Bridge Cup - promised score
2022-07-06 02:38:00 【@Xiaoyu~】
Title Description
If the greatest common divisor of the numerator and denominator of a fraction is 1, This fraction is called a reduced fraction .
for example ,3/4 , 5/2 , 1/8 , 7/1 It's all contract scores .
Excuse me, , How many committed scores are there , The numerator and denominator are 1 To 2020 Integer between ( Include 1 and 2020)?
Topic analysis
Violent search , Judge by the greatest common divisor
1. Import header file first

2. Then design a function to find the greatest common factor of molecules , if 1, Then the score is a reduced score

3. The main function with for loop , Bring each number into the numerator and denominator respectively , then num Count

4. The final result is 2481215

5. The attached total code is as follows
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
// Design masure Function to find the greatest common factor between numerator and denominator
int masure(int i, int n)
{
if (n % i == 0)
{
return i;
}
else if (n % i != 0)
{
return masure(n%i,i);
}
}
int main()
{
int num = 0;
int i = 0;
int n = 0;
// use for Loop so that each number is made a numerator and denominator respectively
for (i = 1; i < 2021; i++)
{
for (n = 1; n < 2021; n++)
{
int x = masure(i,n);
// If the greatest common factor is 1, Then the score is a reduced score
if (x==1)
{
//num Number of Statistics
num++;
}
}
}
printf("%d\n", num);
return 0;
}边栏推荐
- Redis cluster deployment based on redis5
- Zero basic self-study STM32 wildfire review of GPIO use absolute address to operate GPIO
- 2022 China eye Expo, Shandong vision prevention and control exhibition, myopia, China myopia correction Exhibition
- 【MySQL 15】Could not increase number of max_ open_ files to more than 10000 (request: 65535)
- LeetCode 103. Binary tree zigzag level order transverse - Binary Tree Series Question 5
- Keyword static
- How to generate rich text online
- Which ecology is better, such as Mi family, graffiti, hilink, zhiting, etc? Analysis of five mainstream smart brands
- Method of changing object properties
- Thinking on Architecture Design (under continuous updating)
猜你喜欢

Introduction to robotframework (II) app startup of appui automation

Sword finger offer 30 Stack containing min function
![[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 21](/img/73/4050a592fdd99bf06e8fd853b157b6.jpg)
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 21

Pat grade a 1033 to fill or not to fill

PMP每日一练 | 考试不迷路-7.5

Ue4- how to make a simple TPS role (II) - realize the basic movement of the role

Force buckle 146 LRU cache

Paper notes: graph neural network gat
![[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 13](/img/29/49da279efed22706545929157788f0.jpg)
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 13

微软语音合成助手 v1.3 文本转语音工具,真实语音AI生成器
随机推荐
Introduction to robotframework (I) brief introduction and use
Accident index statistics
Shell脚本更新存储过程到数据库
Day 50 - install vsftpd on ceontos6.8
怎么检查GBase 8c数据库中的锁信息?
Shell script updates stored procedure to database
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 9
【无标题】数据库中一条查询SQL执行的过程
HttpRunnerManager安装(三)-Linux下配置myql数据库&初始化数据
有沒有sqlcdc監控多張錶 再關聯後 sink到另外一張錶的案例啊?全部在 mysql中操作
Dachang image library
事故指标统计
Spherical lens and cylindrical lens
Ue4- how to make a simple TPS role (II) - realize the basic movement of the role
【MySQL 15】Could not increase number of max_open_files to more than 10000 (request: 65535)
DDoS attacks - are we really at war?
Is there a case where sqlcdc monitors multiple tables and then associates them to sink to another table? All operations in MySQL
RobotFramework入门(二)appUI自动化之app启动
How to generate rich text online
Redis installation