当前位置:网站首页>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 :
边栏推荐
- [free sharing] kotalog diary2022 plan electronic manual ledger
- Simulation scheduling problem of SystemVerilog (1)
- 【光学】基于matlab介电常数计算【含Matlab源码 1926期】
- Ego planner code parsing Bspline_ Optimizer section (2)
- 第二章:基于分解的求水仙花数,基于组合的求水仙花数, 兰德尔数,求[x,y]内的守形数,探求n位守形数,递推探索n位逐位整除数
- Analysis of dart JSON encoder and decoder
- If the warehouse management communication is not in place, what problems will occur?
- Luogu-p1107 [bjwc2008] Lei Tao's kitten
- Thesis study - 7 Very Deep Convolutional Networks for Large-Scale Image Recognition (3/3)
- Pecan — Overview
猜你喜欢

Using the visualization results, click to appear the corresponding sentence

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

ActiveMQ的基础

I study database at station B (4): DQL

These problems should be paid attention to in the production of enterprise promotional videos

FBI警告:有人利用AI换脸冒充他人身份进行远程面试

我眼中真正优秀的CTO长啥样

Summary of composition materials for 2020 high-frequency examination center of educational resources
![Failed to start component [StandardEngine[Catalina]. StandardHost[localhost]. StandardContext](/img/56/ea61359dd149a49589ba7ad70812a0.jpg)
Failed to start component [StandardEngine[Catalina]. StandardHost[localhost]. StandardContext

During MySQL installation, the download interface is empty, and the components to be downloaded are not displayed. MySQL installer 8.0.28.0 download interface is empty solution
随机推荐
Compared with 4G, what are the advantages of 5g to meet the technical requirements of industry 4.0
High concurrency architecture cache
我們做了一個智能零售結算平臺
Ego planner code parsing Bspline_ Optimizer section (3)
Record: solve the problem that MySQL is not an internal or external command environment variable
Differential constrained SPFA
利用可视化结果,点击出现对应的句子
High concurrency Architecture - distributed search engine (ES)
SQL injection for Web Security (1)
We have built an intelligent retail settlement platform
Simple solution of physical backup and restore of Damon database
math_ Taylor formula
How to design a high concurrency system
第一章:求奇因数代数和,求同吗小数和s(d, n),简化同码小数和s(d, n),拓广同码小数和s(d, n)
Dynamic planning -- expansion topics
Summary of learning materials and notes of Zhang Fei's actual combat electronics 1-31
Summary of composition materials for 2020 high-frequency examination center of educational resources
Pecan — Overview
Redis master-slave synchronization, clustering, persistence
Buuctf's different flags and simplerev