当前位置:网站首页>蓝桥历届真题-既约分数
蓝桥历届真题-既约分数
2022-08-09 13:04:00 【CoolTiger_程序员】
答案:
2481215
思路:
遍历1-2020之间的任意点对,判断gcd是否为1,计数。
使用欧几里得算法(辗转相除法)
#include<stdio.h>
int gcd(int a,int b){
if(b==0) return a;
return gcd(b,a%b);
}
int main(){
int i,j;
int count=0;
for(i=1;i<=2020;i++){
for(j=1;j<=2020;j++){
if(gcd(i,j)==1)
count++;
}
}
printf("%d\n",count);
return 0;
}
2481215
--------------------------------
Process exited after 0.4831 seconds with return value 0
请按任意键继续. . .
边栏推荐
- Q_06_02 类型模型
- 剑指 Offer 43. 1~n 整数中 1 出现的次数(递归、数学)
- FPGA中串口通信的时钟频率和波特率计数
- FFmpeg multimedia file processing (the basic concept of ffmpeg processing stream data)
- 力扣解法汇总1413-逐步求和得到正数的最小值
- jenkins api create custom pipeline
- Professor Chen Qiang's "Machine Learning and R Application" course Chapter 13 Assignment
- 剑指offer,剪绳子2
- Professor Chen Qiang "application in machine learning and R" course chapter 17
- Q_06_04 语句和其他构造
猜你喜欢
随机推荐
The sword refers to the offer, cuts the rope 2
FPGA中串口通信的时钟频率和波特率计数
Rmarkdown教程
陈强教授《机器学习及R应用》课程 第十三章作业
Q_07 词汇表
基于 R 语言的判别分析介绍与实践 LDA和QDA
用plot_hist_numeric()实现画直方图
某高校的R语言数据分析期末作业
陈强教授《机器学习及R应用》课程 第十六章作业
render解析
Dry+Bean+Dataset R语言数据分析,报告英文
RTSP协议的实现
Explanation of RTSP protocol
搭建大型分布式服务(二)搭建会员服务
Draw a histogram with plot_hist_numeric()
jenkins api create custom pipeline
蓝桥杯线上模拟赛——Flex 经典骰子布局
陈强教授《机器学习及R应用》课程 第十四章作业
FFmpeg multimedia file processing (ffmpeg prints audio and video Meta information)
JS本地存储 sessionStorage和localStorage