Codeforces Round #651 (Div. 2) A. Maximum GCD(数论)

题目链接:https://codeforces.com/contest/1370/problem/A

题意

有 $n$ 个数大小分别为 $1$ 到 $n$,找出两个数间最大的 $gcd$ 。

题解

若一个 $gcd$ 存在,则至少要有 $gcd$ 本身和 $2 \times gcd$,那么 $gcd$ 最大即为 $\lfloor \frac{n}{2} \rfloor$ 。

代码

#include <bits/stdc++.h>
using namespace std;

void solve() {
    int n; cin >> n;
    cout << n / 2 << "\n";
}

int main() {
    int t; cin >> t;
    while (t--) solve();
}

猜你喜欢

转载自www.cnblogs.com/Kanoon/p/13179361.html