本文主要是介绍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;
}
这篇关于A. Maximize?的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!