当前位置:网站首页>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;
}
边栏推荐
- Day 50 - install vsftpd on ceontos6.8
- Follow the mouse's angle and keyboard events
- 2022 eye health exhibition, vision rehabilitation exhibition, optometry equipment exhibition, eye care products exhibition, eye mask Exhibition
- Gifcam v7.0 minimalist GIF animation recording tool Chinese single file version
- Solution: attributeerror: 'STR' object has no attribute 'decode‘
- 好用的 JS 脚本
- 【MySQL 15】Could not increase number of max_ open_ files to more than 10000 (request: 65535)
- 爬虫(9) - Scrapy框架(1) | Scrapy 异步网络爬虫框架
- UE4 - how to make a simple TPS role (I) - create a basic role
- Paper notes: graph neural network gat
猜你喜欢
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 20
Li Kou today's question -729 My schedule I
一位博士在华为的22年
淘宝焦点图布局实战
Zero basic self-study STM32 wildfire review of GPIO use absolute address to operate GPIO
Apt installation ZABBIX
GifCam v7.0 极简GIF动画录制工具中文单文件版
Easy to use js script
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 17
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 16
随机推荐
Advanced technology management - what is the physical, mental and mental strength of managers
Day 50 - install vsftpd on ceontos6.8
MySQL (IV) - transactions
inherited constructors
I changed the driver to 5.1.35, but it is still the same error. I can succeed even now, but I will report this every time I do an SQL operation
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 19
Paper notes: limit multi label learning galaxc (temporarily stored, not finished)
Force buckle 146 LRU cache
Accident index statistics
GifCam v7.0 极简GIF动画录制工具中文单文件版
High number_ Vector algebra_ Unit vector_ Angle between vector and coordinate axis
How to generate rich text online
Method of changing object properties
Patch NTP server at the beginning of DDoS counterattack
更换gcc版本后,编译出现make[1]: cc: Command not found
Minecraft 1.18.1, 1.18.2 module development 22 Sniper rifle
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 14
General process of machine learning training and parameter optimization (discussion)
事故指标统计
[matlab] access of variables and files