当前位置:网站首页>Chapter 2: find the classical solution of the maximum Convention and the least common multiple of a and B, find the conventional solution of the maximum Convention and the least common multiple of a a
Chapter 2: find the classical solution of the maximum Convention and the least common multiple of a and B, find the conventional solution of the maximum Convention and the least common multiple of a a
2022-07-03 19:21:00 【Shares_ four】
// seek a,b Classical solution of maximum Convention and least common multiple of
int main()
{
long a, b, c, r, a1, b1;
printf(" Please enter a positive integer a,b: ");
scanf("%ld,%ld", &a, &b);
if (a < b)
{
c = a;
a = b;
b = c;
}
a1 = a;
b1 = b;
r = a % b;
while (r != 0) // The implementation of “ division algorithm
{
a = b;
b = r;
r = a % b;
}
printf("(%ld,%ld) = %ld\n", a1, b1, b);
printf("{%ld,%ld} = %ld\n", a1, b1, a1 * b1 / b);
return 0;
}
result :
// seek a,b The conventional solution of the maximum Convention and the least common multiple of
int main()
{
long a, b, c;
printf(" Please enter a positive integer a,b: ");
scanf("%ld,%ld", &a, &b);
if (a < b)
{
c = a;
a = b;
b = c;
}
for (c = b; c >= 1; c--)
if (a % c == 0 && b % c == 0) break; //C Is the trial quotient factor
printf("(%ld,%ld) = %ld\n", a, b, c);
printf("{%ld,%ld} = %ld\n", a, b, a * b / c);
return 0;
}
result :
// seek n The maximum Convention and the least common multiple of positive integers
int main()
{
int k, n;
long a, b, c, m[100];
printf(" Please enter the number of positive integers n: ");
scanf("%d", &n);
printf(" Please input... In turn %d A positive integer :", n);
for (k = 0; k <= n - 1; k++)
{
printf("\n Please enter the first %d A positive integer :", k + 1);
scanf(" %ld", &m[k]); // Input raw data
}
b = m[0];
for (k = 1; k <= n - 1; k++) // Cycle calculation n - 1 Time
{
a = m[k];
if (a < b)
{
c = a;
a = b; // In exchange for a、b, Make sure a>b
b = c;
}
for (c = b; c >= 1; c--)
if (a % c == 0 && b % c == 0) break; // Calculate the greatest common divisor
if (c == 1) break; // If the greatest common divisor is 1, Exit loop
b = c;
}
printf(" (%ld", m[0]); // Output the result of the greatest common divisor
for (k = 1; k <= n - 1; k++)
printf(", %ld", m[k]);
printf(") = %ld\n", c);
b = m[0];
for (k = 1; k <= n - 1; k++) // Cycle calculation n-1 Time
{
a = m[k];
if (a < b)
{
c = a;
a = b;
b = c;
}
for (c = a; c <= a * b; c = c + a)
if (c % b == 0) break;
b = c;
}
printf("{%ld", m[0]);
for (k = 1; k <= n - 1; k++)
printf(",%ld", m[k]);
printf("}=%ld\n", c);
return 0;
}
result :
边栏推荐
- 第二章:4位卡普雷卡数,搜索偶数位卡普雷卡数,搜索n位2段和平方数,m位不含0的巧妙平方数,指定数字组成没有重复数字的7位平方数,求指定区间内的勾股数组,求指定区间内的倒立勾股数组
- Day_ 18 IO stream system
- Php based campus lost and found platform (automatic matching push)
- Day11 ---- 我的页面, 用户信息获取修改与频道接口
- Simple solution of physical backup and restore of Damon database
- Pecan - route
- If the warehouse management communication is not in place, what problems will occur?
- The most valuable thing
- Sentinel source code analysis part I sentinel overview
- 第一章:求所有阶乘和数,大奖赛现场统分程序设计,三位阶乘和数,图形点扫描,递归求n的阶乘n!,求n的阶乘n!,舍罕王失算
猜你喜欢
第二章:基于分解的求水仙花数,基于组合的求水仙花数, 兰德尔数,求[x,y]内的守形数,探求n位守形数,递推探索n位逐位整除数
01 - QT OpenGL display OpenGL window
第一章:拓广同码小数和s(d, n)
Record: install MySQL on ubuntu18.04
What is the content of game modeling
Record: writing MySQL commands
Analysis of dart JSON encoder and decoder
Dart JSON编码器和解码器剖析
Using the visualization results, click to appear the corresponding sentence
第一章:求同吗小数和s(d, n)
随机推荐
UE source code analysis: uccharactermovementcomponent - rootmotion
交叉编译Opencv带Contrib
第一章: 舍罕王失算
第二章:4位卡普雷卡数,搜索偶数位卡普雷卡数,搜索n位2段和平方数,m位不含0的巧妙平方数,指定数字组成没有重复数字的7位平方数,求指定区间内的勾股数组,求指定区间内的倒立勾股数组
Differential constrained SPFA
【水质预测】基于matlab模糊神经网络水质预测【含Matlab源码 1923期】
Smart wax therapy machine based on STM32 and smart cloud
为什么要做特征的归一化/标准化?
Common text labels
【光学】基于matlab涡旋光产生【含Matlab源码 1927期】
math_泰勒公式
Ctrip will implement a 3+2 work system in March, with 3 days on duty and 2 days at home every week
第二章:基于分解的求水仙花数,基于组合的求水仙花数, 兰德尔数,求[x,y]内的守形数,探求n位守形数,递推探索n位逐位整除数
Free year-end report summary template Welfare Collection
第二章:求长方体数组,指定区间内的完全数,改进指定区间内的完全数
flask 生成swagger文档
Pecan — Overview
EGO Planner代码解析bspline_optimizer部分(3)
第二十章:y= sin(x)/x,漫步坐标系计算,y= sin(x)/x 带廓幅图形,奥运五环,小球滚动与弹跳,流水显示,矩形优化裁剪,r个皇后全控nxn棋盘
Record: solve the problem that MySQL is not an internal or external command environment variable