当前位置: 首页 > news >正文

A. Maximize?

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given an integer x𝑥. Your task is to find any integer y𝑦 (1≤y<x)(1≤𝑦<𝑥) such that gcd(x,y)+ygcd(𝑥,𝑦)+𝑦 is maximum possible.

Note that if there is more than one y𝑦 which satisfies the statement, you are allowed to find any.

gcd(a,b)gcd(𝑎,𝑏) is the Greatest Common Divisor of a𝑎 and b𝑏. For example, gcd(6,4)=2gcd(6,4)=2.

Input

The first line contains a single integer t𝑡 (1≤t≤10001≤𝑡≤1000) — the number of test cases.

Each of the following t𝑡 lines contains a single integer x𝑥 (2≤x≤10002≤𝑥≤1000).

Output

For each test case, output any y𝑦 (1≤y<x1≤𝑦<𝑥), which satisfies the statement.

Example

input

Copy

 

7

10

7

21

100

2

1000

6

output

Copy

5
6
18
98
1
750
3

解题说明:此题是一道数学题,分析后能知道最大肯定不会超过x,可以采用贪心算法,y选择为x-1,这样gcd(x,y)为0,则最大值就是x-1

#include <stdio.h>int main()
{int t = 0, n = 0;scanf("%d", &t);while (t--){scanf("%d", &n);printf("%d\n", n - 1);}return 0;
}

http://www.lryc.cn/news/354181.html

相关文章:

  • RBAC 动态权限
  • c语言:模拟strlen(三种方法)最全版本
  • 线性模型--普通最小二乘法
  • 移动云以深度融合之服务,令“大”智慧贯穿云端
  • 簡述vue常用指令
  • 【建议收藏】用AI快速生成一个网页(名侦探柯南~灰原哀主题网页),适合大学生web期末大作业
  • 用c++用4个凸函数(觉得啥好用用啥)去测试adam,rmsprop,adagrad算法的性能(谁先找到最优点)
  • AJAX初级
  • 重载大于号运算符,比较复数大小
  • go ast语义分析实现指标计算器
  • 【Vue】组件间传参与方法调用
  • 类和对象2
  • Linux系统命令traceroute详解(语法、选项、原理和实例)
  • 中兴通讯助力中国移动,推动SPN AI节能技术于23省规模部署
  • SQL Server--死锁
  • 中科蓝讯AB32VG1中文寄存器说明GPIO端口操作
  • 如何查看热门GPT应用?
  • C++中的各种定义
  • Java面向对象-常用类(日期时间类)
  • Shell环境变量深入:自定义系统环境变量
  • 【C++课程学习】:命名空间的理解(图文详解)
  • 鸿蒙ArkUI-X平台差异化:【运行态差异化(@ohos.deviceInfo)】
  • 蓝牙Mesh模块组网时无线回程影响速率吗?
  • 将3D检测的box框投影到BEV图片上
  • Flutter 中的 ClipOval 小部件:全面指南
  • ubuntu 硬盘转移
  • three.js中使用CameraHelper来可视化调整阴影相机的范围
  • Golang发送GET请求并设置查询参数
  • c++笔记3
  • 唠唠叨叨,每日进度