CF1370A.Maximum GCD

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Let's consider all integers in the range from 11 to nn (inclusive).

Among all pairs of distinct integers in this range, find the maximum possible greatest common divisor of integers in pair. Formally, find the maximum value of gcd(a,b)\mathrm{gcd}(a, b), where 1≤a<b≤n1 \leq a \lt b \leq n.

The greatest common divisor, gcd(a,b)\mathrm{gcd}(a, b), of two positive integers aa and bb is the biggest integer that is a divisor of both aa and bb.

考虑所有在 11 到 nn(含端点)范围内的整数。

在该范围内所有互不相同的整数对中,找出整数对中两数的最大可能最大公约数。形式化地说,即求 gcd(a,b)\mathrm{gcd}(a, b) 的最大值,其中 1≤a<b≤n1 \leq a \lt b \leq n。

两个正整数 aa 和 bb 的最大公约数 gcd(a,b)\mathrm{gcd}(a, b) 是同时整除 aa 和 bb 的最大整数。

输入格式

The first line contains a single integer tt (1≤t≤1001 \leq t \leq 100) — the number of test cases. The description of the test cases follows.

The only line of each test case contains a single integer nn (2≤n≤1062 \leq n \leq 10^6).

第一行包含一个整数 tt(1≤t≤1001 \leq t \leq 100)—— 表示测试用例的数量。随后是各测试用例的描述。

每个测试用例仅有一行,包含一个整数 nn(2≤n≤1062 \leq n \leq 10^6)。

输出格式

For each test case, output the maximum value of gcd(a,b)\mathrm{gcd}(a, b) among all 1≤a<b≤n1 \leq a \lt b \leq n.

对于每个测试用例,输出所有满足 1≤a<b≤n1 \leq a \lt b \leq n 的整数对 (a,b)(a, b) 中 gcd(a,b)\mathrm{gcd}(a, b) 的最大值。

输入输出样例

  • 输入#1

    2
    3
    5

    输出#1

    1
    2

说明/提示

In the first test case, gcd(1,2)=gcd(2,3)=gcd(1,3)=1\mathrm{gcd}(1, 2) = \mathrm{gcd}(2, 3) = \mathrm{gcd}(1, 3) = 1.

In the second test case, 22 is the maximum possible value, corresponding to gcd(2,4)\mathrm{gcd}(2, 4).

在第一个测试用例中,gcd(1,2)=gcd(2,3)=gcd(1,3)=1\mathrm{gcd}(1, 2) = \mathrm{gcd}(2, 3) = \mathrm{gcd}(1, 3) = 1。

在第二个测试用例中,最大可能值为 22,对应于 gcd(2,4)\mathrm{gcd}(2, 4)。

输入解题思路,AI测评打分。不知道怎么写?

首页