当前位置:网站首页>Leshan normal programming competition 2020-g: maximum common divisor [thinking]
Leshan normal programming competition 2020-g: maximum common divisor [thinking]
2022-07-20 10:02:00 【Starry sky and bright moon】
Title Description
Give a number n, Any other integer a and b The greatest common divisor of is gcd(a, b), The solution comes from 1 To n The maximum value of the greatest common divisor of any two different integers in .
Review of the greatest common divisor :
18 The number of divisors is 1,2,3,6,9,18;
24 The number of divisors is 1,2,3,4,6,8,12,24;
18 And 24 The greatest common divisor of is 6.
Input
Input includes multiple sets of data ;
The first line has only one integer t (1 ≤ t ≤ 100) Represents the number of groups of input data ;
Next input t That's ok , Each line contains only one positive integer n(2 ≤ n ≤ 106).
Output
For each group of input , Output required gcd(a, b) The maximum of , among 1 ≤ a < b ≤ n.
The sample input
2
3
5
Sample output
1
2
Tips
For the first set of data ,gcd(1, 2) = gcd(2, 3) = gcd(1,3) = 1;
For the second set of data ,gcd(2, 4) = 2 Is the biggest possible result .
Ideas
1. When n In the case of an even number :
[1, n] The greatest common divisor of two different numbers in must be n and n/2. So the answer is n/2.
2. When n In the case of an odd number :
[1, n] The greatest common divisor of two different numbers in must be n-1 and (n - 1) / 2. So the answer is (n - 1) / 2.
AC Code
#include<cstdio>
using namespace std;
typedef long long ll;
const int MAXN = 1e5 + 5;
void solve() {
int n;
scanf("%d", &n);
printf("%d\n", n / 2);
}
int main() {
int t;
scanf("%d", &t);
for (int i = 0; i < t; ++i) {
solve();
}
return 0;
}
边栏推荐
- SCU of zynq ARM core
- 川菜菜谱(一)
- Typical HMI application implementation scheme can help you better carry out master control selection
- 【OpenCV】边缘检测 [API与源码实现]
- Allegro cannot display drill legend information when adding drill legend
- i. Mx8mp development board porting USBWiFi rtl8192eu driver
- 【BOM】初识BOM~
- Least square linear fitting and its code implementation (C language)
- FreeRTOS thread safe and interrupt safe printf implementation
- 计算机408+数据库【适合考研复试或期末复习】
猜你喜欢
Detailed explanation of the principle of triode series linear voltage stabilizing circuit and Multisim Simulation
Evaluate reading and writing speed and network of Reza rz/g2l storage
Wireless network test based on Feiling NXP i.mx6ull
多基线干涉仪系统测向误差分析
如何把一个“平台” 塞进一个小盒子里?(下)|技术实现篇
After ise14.7 was installed in win10 system, the software flashed back and the driver could not be installed normally
Vulnhub target jangow: 1.0.1
How to set the oil on the through hole cover when exporting the Gerber file of PCB
2022 -7-18 第八小组 顾宇佳 学习笔记
基于循环卷积的一维小波变换程序验证(C语言)
随机推荐
FPGA network port implementation and detailed explanation (3)
Connaissance de la technologie des tunnels d'infiltration Intranet
[DOM] first knowledge of DOM
vulnhub 靶机 Jangow: 1.0.1
RDO deployment openstack single node
Qt给控件添加鼠标事件
提升开发效率的 Chrome 开发者工具快捷键参考
Leshan normal programming competition 2020-b: design web page [prime number]
Experience of installing ROS in Jetson nano (failed)
SCU of zynq ARM core
FreeRTOS线程安全、中断安全的printf实现方式
Bing Bing search doesn't work
三极管串联线性稳压电路原理详解及Multisim仿真
Master Karnaugh map simplification in one minute
Solution of STM32 cubeide breakpoint failure
代码审计之企业级进销存管理系统
[BOM] first knowledge of BOM~
Servlet概述
The end result of printf - where is the data printed
LeetCode:第302场周赛(总结)