当前位置:网站首页>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 :
边栏推荐
- P3402 persistent and searchable
- Sentinel source code analysis part II - sentinel dashboard console startup and configuration
- 为什么要做特征的归一化/标准化?
- Using the visualization results, click to appear the corresponding sentence
- 第一章:喝汽水,阶梯电费计算,阶梯电费计算函数,个人所税,求解平方根不等式,简化求解平方根不等式,求解调和级数不等式,解不等式:d<1+1/2-1/3+1/4+1/5-1/6+..士1/n
- Summary of composition materials for 2020 high-frequency examination center of educational resources
- Free hand account sharing in September - [cream Nebula]
- Flask generates swagger documents
- High concurrency architecture cache
- Verilog HDL continuous assignment statement, process assignment statement, process continuous assignment statement
猜你喜欢

Octopus online ecological chain tour Atocha protocol received near grant worth $50000

01. Preparation for automated office (free guidance, only three steps)

Think of new ways

Sentinel source code analysis part II - sentinel dashboard console startup and configuration

【LeetCode】【SQL】刷题笔记

第二十章:y= sin(x)/x,漫步坐标系计算,y= sin(x)/x 带廓幅图形,奥运五环,小球滚动与弹跳,流水显示,矩形优化裁剪,r个皇后全控nxn棋盘

第一章:求奇因数代数和,求同吗小数和s(d, n),简化同码小数和s(d, n),拓广同码小数和s(d, n)

The online customer service system developed by PHP is fully open source without encryption, and supports wechat customer service docking

The earliest record

05 -- QT OpenGL draw cube uniform
随机推荐
Record: install MySQL on ubuntu18.04
High concurrency architecture cache
Analyse du Code du planificateur ego bspline Section Optimizer (1)
Pecan - route
我们做了一个智能零售结算平台
Why should the gradient be manually cleared before back propagation in pytorch?
EGO Planner代码解析bspline_optimizer部分(1)
Record: solve the problem that MySQL is not an internal or external command environment variable
【LeetCode】【SQL】刷题笔记
【Proteus仿真】用24C04与1602LCD设计的简易加密电子密码锁
Zhang Fei hardware 90 day learning notes - personal records on day 4, please see my personal profile / homepage for the complete
Pecan — @expose()
Floating source code comment (38) parallel job processor
Bad mentality leads to different results
Valentine's Day - make an exclusive digital collection for your lover
01. Preparation for automated office (free guidance, only three steps)
FBI警告:有人利用AI换脸冒充他人身份进行远程面试
[disease identification] machine vision lung cancer detection system based on Matlab GUI [including Matlab source code 1922]
Merge K ascending linked lists
第一章: 舍罕王失算